diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 1f9f9661160..a883cc6f02c 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -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. */ diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index df06d9c0f32..9c78a2d1b10 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -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 }