You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/22 06:50:57 UTC
[incubator-nuttx] 03/04: libc/semaphore:sem_init change defult protocol
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 577e550698610ba46fb35c2288e110fd2135d507
Author: anjiahao <an...@xiaomi.com>
AuthorDate: Fri Dec 24 10:42:09 2021 +0800
libc/semaphore:sem_init change defult protocol
Signed-off-by: anjiahao <an...@xiaomi.com>
---
include/nuttx/mutex.h | 1 +
include/semaphore.h | 5 ++++-
libs/libc/semaphore/sem_getprotocol.c | 6 +++---
sched/semaphore/sem_holder.c | 2 +-
sched/semaphore/sem_setprotocol.c | 4 ++--
5 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/include/nuttx/mutex.h b/include/nuttx/mutex.h
index 129521f06d..814da6adcd 100644
--- a/include/nuttx/mutex.h
+++ b/include/nuttx/mutex.h
@@ -98,6 +98,7 @@ static inline int nxmutex_init(FAR mutex_t *mutex)
return _SEM_ERRVAL(ret);
}
+ _SEM_SETPROTOCOL(mutex, SEM_PRIO_INHERIT);
return ret;
}
diff --git a/include/semaphore.h b/include/semaphore.h
index 346e8d2d39..8d5a559338 100644
--- a/include/semaphore.h
+++ b/include/semaphore.h
@@ -48,7 +48,10 @@
/* Bit definitions for the struct sem_s flags field */
-#define PRIOINHERIT_FLAGS_DISABLE (1 << 0) /* Bit 0: Priority inheritance
+#define PRIOINHERIT_FLAGS_ENABLE (1 << 0) /* Bit 0: Priority inheritance
+ * is enabled for this semaphore. */
+
+#define PRIOINHERIT_FLAGS_DISABLE (0 << 0) /* Bit 0: Priority inheritance
* is disabled for this semaphore. */
/****************************************************************************
diff --git a/libs/libc/semaphore/sem_getprotocol.c b/libs/libc/semaphore/sem_getprotocol.c
index 2dfac140fe..6339d736ed 100644
--- a/libs/libc/semaphore/sem_getprotocol.c
+++ b/libs/libc/semaphore/sem_getprotocol.c
@@ -55,13 +55,13 @@ int sem_getprotocol(FAR sem_t *sem, FAR int *protocol)
DEBUGASSERT(sem != NULL && protocol != NULL);
#ifdef CONFIG_PRIORITY_INHERITANCE
- if ((sem->flags & PRIOINHERIT_FLAGS_DISABLE) != 0)
+ if ((sem->flags & PRIOINHERIT_FLAGS_ENABLE) != 0)
{
- *protocol = SEM_PRIO_NONE;
+ *protocol = SEM_PRIO_INHERIT;
}
else
{
- *protocol = SEM_PRIO_INHERIT;
+ *protocol = SEM_PRIO_NONE;
}
#else
diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c
index e2cc379015..8564211c30 100644
--- a/sched/semaphore/sem_holder.c
+++ b/sched/semaphore/sem_holder.c
@@ -707,7 +707,7 @@ void nxsem_add_holder_tcb(FAR struct tcb_s *htcb, FAR sem_t *sem)
* inheritance is effectively disabled.
*/
- if (htcb->flink != NULL && (sem->flags & PRIOINHERIT_FLAGS_DISABLE) == 0)
+ if (htcb->flink != NULL && (sem->flags & PRIOINHERIT_FLAGS_ENABLE) != 0)
{
/* Find or allocate a container for this new holder */
diff --git a/sched/semaphore/sem_setprotocol.c b/sched/semaphore/sem_setprotocol.c
index ee1319cf03..ca8042afa1 100644
--- a/sched/semaphore/sem_setprotocol.c
+++ b/sched/semaphore/sem_setprotocol.c
@@ -82,7 +82,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
/* Disable priority inheritance */
- sem->flags |= PRIOINHERIT_FLAGS_DISABLE;
+ sem->flags &= ~PRIOINHERIT_FLAGS_ENABLE;
/* Remove any current holders */
@@ -93,7 +93,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
/* Enable priority inheritance (dangerous) */
- sem->flags &= ~PRIOINHERIT_FLAGS_DISABLE;
+ sem->flags |= PRIOINHERIT_FLAGS_ENABLE;
return OK;
case SEM_PRIO_PROTECT: