sched/semaphore: check sem flags before enable priority inheritance
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
parent
0113865bb0
commit
8b5078fc36
@ -72,6 +72,9 @@ int nxsem_post(FAR sem_t *sem)
|
||||
FAR struct tcb_s *stcb = NULL;
|
||||
irqstate_t flags;
|
||||
int16_t sem_count;
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
uint8_t prioinherit;
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(sem != NULL);
|
||||
|
||||
@ -118,8 +121,13 @@ int nxsem_post(FAR sem_t *sem)
|
||||
* will do nothing.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
prioinherit = sem->flags & PRIOINHERIT_FLAGS_ENABLE;
|
||||
if (prioinherit != 0)
|
||||
{
|
||||
sched_lock();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If the result of semaphore unlock is non-positive, then
|
||||
* there must be some task waiting for the semaphore.
|
||||
*/
|
||||
@ -180,8 +188,11 @@ int nxsem_post(FAR sem_t *sem)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
nxsem_restore_baseprio(stcb, sem);
|
||||
sched_unlock();
|
||||
if (prioinherit != 0)
|
||||
{
|
||||
nxsem_restore_baseprio(stcb, sem);
|
||||
sched_unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Interrupts may now be enabled. */
|
||||
|
@ -107,6 +107,10 @@ int nxsem_wait(FAR sem_t *sem)
|
||||
|
||||
else
|
||||
{
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
uint8_t prioinherit = sem->flags & PRIOINHERIT_FLAGS_ENABLE;
|
||||
#endif
|
||||
|
||||
/* First, verify that the task is not already waiting on a
|
||||
* semaphore
|
||||
*/
|
||||
@ -126,18 +130,22 @@ int nxsem_wait(FAR sem_t *sem)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
/* Disable context switching. The following operations must be
|
||||
* atomic with regard to the scheduler.
|
||||
*/
|
||||
if (prioinherit != 0)
|
||||
{
|
||||
/* Disable context switching. The following operations must be
|
||||
* atomic with regard to the scheduler.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
sched_lock();
|
||||
|
||||
/* Boost the priority of any threads holding a count on the
|
||||
* semaphore.
|
||||
*/
|
||||
/* Boost the priority of any threads holding a count on the
|
||||
* semaphore.
|
||||
*/
|
||||
|
||||
nxsem_boost_priority(sem);
|
||||
nxsem_boost_priority(sem);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the errno value to zero (preserving the original errno)
|
||||
* value). We reuse the per-thread errno to pass information
|
||||
* between sem_waitirq() and this functions.
|
||||
@ -201,7 +209,10 @@ int nxsem_wait(FAR sem_t *sem)
|
||||
ret = rtcb->errcode != OK ? -rtcb->errcode : OK;
|
||||
|
||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
||||
sched_unlock();
|
||||
if (prioinherit != 0)
|
||||
{
|
||||
sched_unlock();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user