open ffrt recursive mutex

Signed-off-by: yuanzhipu <2710242656@qq.com>
This commit is contained in:
yuanzhipu 2024-08-13 16:53:10 +08:00
parent 439d5bb6cc
commit 22b1e86057
2 changed files with 64 additions and 0 deletions

View File

@ -39,6 +39,53 @@
#define FFRT_API_C_MUTEX_H
#include "type_def.h"
/**
* @brief Initializes mutex attr.
*
* @param mutex Indicates a pointer to the mutex.
* @param attr Indicates a pointer to the mutex attribute.
* @return {@link ffrt_success} 0 - success
{@link ffrt_error_inval} 22 - if attr is null.
* @since 12
* @version 1.0
*/
FFRT_C_API int ffrt_mutexattr_init(ffrt_mutexattr_t* attr);
/**
* @brief set mutex type.
*
* @param attr Indicates a pointer to the mutex attribute.
* @param type Indicates a int to the mutex type.
* @return {@link ffrt_success} 0 - success
{@link ffrt_error_inval} 22 - if attr is null or type is not 0 or 2.
* @since 12
* @version 1.0
*/
FFRT_C_API int ffrt_mutexattr_settype(ffrt_mutexattr_t* attr, int type);
/**
* @brief get mutex type.
*
* @param attr Indicates a pointer to the mutex attribute.
* @param type Indicates a pointer to the mutex type.
* @return {@link ffrt_success} 0 - success
{@link ffrt_error_inval} 22 - if attr is null or type is null.
* @since 12
* @version 1.0
*/
FFRT_C_API int ffrt_mutexattr_gettype(ffrt_mutexattr_t* attr, int* type);
/**
* @brief destroy mutex attr, the user needs to invoke this interface.
*
* @param attr Indicates a pointer to the mutex attribute.
* @return {@link ffrt_success} 0 - success
{@link ffrt_error_inval} 22 - if attr is null.
* @since 12
* @version 1.0
*/
FFRT_C_API int ffrt_mutexattr_destroy(ffrt_mutexattr_t* attr);
/**
* @brief Initializes a mutex.
*

View File

@ -183,6 +183,23 @@ typedef struct {
long storage;
} ffrt_mutexattr_t;
/**
* @brief ffrt mutex type enum
*
* Describes the mutex type, ffrt_mutex_normal is normal mutex;
* ffrt_mutex_recursive is recursive mutex, ffrt_mutex_default is normal mutex.
*
* @since 12
*/
typedef enum {
/** ffrt normal mutex type */
ffrt_mutex_normal = 0,
/** ffrt recursive mutex type */
ffrt_mutex_recursive = 2,
/** ffrt default mutex type */
ffrt_mutex_default = ffrt_mutex_normal
} ffrt_mutex_type;
typedef struct {
uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
} ffrt_mutex_t;