libc/semaphore:sem_init change defult protocol

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao
2021-12-24 10:42:09 +08:00
committed by Xiang Xiao
parent e1ca516488
commit 577e550698
5 changed files with 11 additions and 7 deletions
+1
View File
@@ -98,6 +98,7 @@ static inline int nxmutex_init(FAR mutex_t *mutex)
return _SEM_ERRVAL(ret); return _SEM_ERRVAL(ret);
} }
_SEM_SETPROTOCOL(mutex, SEM_PRIO_INHERIT);
return ret; return ret;
} }
+4 -1
View File
@@ -48,7 +48,10 @@
/* Bit definitions for the struct sem_s flags field */ /* 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. */ * is disabled for this semaphore. */
/**************************************************************************** /****************************************************************************
+3 -3
View File
@@ -55,13 +55,13 @@ int sem_getprotocol(FAR sem_t *sem, FAR int *protocol)
DEBUGASSERT(sem != NULL && protocol != NULL); DEBUGASSERT(sem != NULL && protocol != NULL);
#ifdef CONFIG_PRIORITY_INHERITANCE #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 else
{ {
*protocol = SEM_PRIO_INHERIT; *protocol = SEM_PRIO_NONE;
} }
#else #else
+1 -1
View File
@@ -707,7 +707,7 @@ void nxsem_add_holder_tcb(FAR struct tcb_s *htcb, FAR sem_t *sem)
* inheritance is effectively disabled. * 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 */ /* Find or allocate a container for this new holder */
+2 -2
View File
@@ -82,7 +82,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
/* Disable priority inheritance */ /* Disable priority inheritance */
sem->flags |= PRIOINHERIT_FLAGS_DISABLE; sem->flags &= ~PRIOINHERIT_FLAGS_ENABLE;
/* Remove any current holders */ /* Remove any current holders */
@@ -93,7 +93,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
/* Enable priority inheritance (dangerous) */ /* Enable priority inheritance (dangerous) */
sem->flags &= ~PRIOINHERIT_FLAGS_DISABLE; sem->flags |= PRIOINHERIT_FLAGS_ENABLE;
return OK; return OK;
case SEM_PRIO_PROTECT: case SEM_PRIO_PROTECT: