From 1711a298a82f5dfa4ff36e06e4994dbddadf572d Mon Sep 17 00:00:00 2001 From: anjiahao Date: Mon, 19 Jun 2023 15:49:45 +0800 Subject: [PATCH] libc/semaphore:Set the flag need AND SEM_PRIO_MASK Signed-off-by: anjiahao --- libs/libc/misc/lib_mutex.c | 4 ++++ libs/libc/semaphore/sem_setprotocol.c | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/libc/misc/lib_mutex.c b/libs/libc/misc/lib_mutex.c index 4e8f53d484..c43d324d6d 100644 --- a/libs/libc/misc/lib_mutex.c +++ b/libs/libc/misc/lib_mutex.c @@ -89,7 +89,11 @@ int nxmutex_init(FAR mutex_t *mutex) } mutex->holder = NXMUTEX_NO_HOLDER; +#ifdef CONFIG_PRIORITY_INHERITANCE _SEM_SETPROTOCOL(&mutex->sem, SEM_TYPE_MUTEX | SEM_PRIO_INHERIT); +#else + _SEM_SETPROTOCOL(&mutex->sem, SEM_TYPE_MUTEX); +#endif return ret; } diff --git a/libs/libc/semaphore/sem_setprotocol.c b/libs/libc/semaphore/sem_setprotocol.c index c377a918ee..2713744865 100644 --- a/libs/libc/semaphore/sem_setprotocol.c +++ b/libs/libc/semaphore/sem_setprotocol.c @@ -77,20 +77,21 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol) { DEBUGASSERT(sem != NULL); - switch (protocol) + switch (protocol & SEM_PRIO_MASK) { case SEM_PRIO_NONE: - return OK; + break; case SEM_PRIO_INHERIT: case SEM_PRIO_PROTECT: return -ENOTSUP; default: - break; + return -EINVAL; } - return -EINVAL; + sem->flags = protocol; + return OK; } /****************************************************************************