From d2be4d7a460365844a7732df8a3eb59e6bb64897 Mon Sep 17 00:00:00 2001 From: zhushengle Date: Sat, 30 Oct 2021 15:19:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81pthread=5Fmutex?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接口列表: pthread_mutexattr_init pthread_mutexattr_settype pthread_mutexattr_destroy Close #I4G4RQ Signed-off-by: zhushengle Change-Id: I7aea47e375ffe961a3dcbf39da6b84561e3d0a8f --- kal/posix/src/pthread_mutex.c | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/kal/posix/src/pthread_mutex.c b/kal/posix/src/pthread_mutex.c index fdd81eca..60ecc71b 100644 --- a/kal/posix/src/pthread_mutex.c +++ b/kal/posix/src/pthread_mutex.c @@ -31,6 +31,7 @@ #include #include +#include #include "los_compiler.h" #include "los_mux.h" #include "errno.h" @@ -61,13 +62,53 @@ static inline int MapError(UINT32 err) } } +int pthread_mutexattr_init(pthread_mutexattr_t *mutexAttr) +{ + if (mutexAttr == NULL) { + return EINVAL; + } + + mutexAttr->type = PTHREAD_MUTEX_RECURSIVE; + return 0; +} + +int pthread_mutexattr_settype(pthread_mutexattr_t *mutexAttr, int type) +{ + if (mutexAttr == NULL) { + return EINVAL; + } + + if (((unsigned)type != PTHREAD_MUTEX_NORMAL) && + ((unsigned)type != PTHREAD_MUTEX_RECURSIVE) && + ((unsigned)type != PTHREAD_MUTEX_ERRORCHECK)) { + return EINVAL; + } + + if ((unsigned)type != PTHREAD_MUTEX_RECURSIVE) { + return EOPNOTSUPP; + } + + mutexAttr->type = PTHREAD_MUTEX_RECURSIVE; + return 0; +} + +int pthread_mutexattr_destroy(pthread_mutexattr_t *mutexAttr) +{ + if (mutexAttr == NULL) { + return EINVAL; + } + + (VOID)memset_s(mutexAttr, sizeof(pthread_mutexattr_t), 0, sizeof(pthread_mutexattr_t)); + return 0; +} + /* Initialize mutex. If mutexAttr is NULL, use default attributes. */ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexAttr) { UINT32 muxHandle; UINT32 ret; - if (mutexAttr != NULL) { + if ((mutexAttr != NULL) && (mutexAttr->type != PTHREAD_MUTEX_RECURSIVE)) { return EOPNOTSUPP; }