This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 922426346e1e4fad67a171f20b34cdadbb0b47d6 Author: p-gaoxiang43 <[email protected]> AuthorDate: Mon Aug 4 20:33:22 2025 +0800 sched/semaphore: remove dead code if no CONFIG_PRIORITY_PROTEC Consolidate CONFIG_PRIORITY_PROTECT checks by moving macro definitions to their actual usage locations and removing duplicate/dead code in semaphore implementation. This reduces code duplication and improves maintainability across sem_wait, sem_trywait, and sem_post functions. Signed-off-by: p-gaoxiang43 <[email protected]> --- sched/semaphore/sem_post.c | 2 ++ sched/semaphore/sem_trywait.c | 4 +++- sched/semaphore/sem_wait.c | 4 +++- sched/semaphore/semaphore.h | 3 --- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 26f17e63b58..6818940873b 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -246,7 +246,9 @@ int nxsem_post_slow(FAR sem_t *sem) } else if (proto == SEM_PRIO_PROTECT) { +#ifdef CONFIG_PRIORITY_PROTECT nxsem_protect_post(sem); +#endif } sched_unlock(); diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index 73ae795f9bb..5f753cb9cf9 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -63,7 +63,7 @@ int nxsem_trywait_slow(FAR sem_t *sem) { irqstate_t flags; - int ret = -EAGAIN; + int ret = OK; bool mutex = NXSEM_IS_MUTEX(sem); FAR atomic_t *val = mutex ? NXSEM_MHOLDER(sem) : NXSEM_COUNT(sem); int32_t old; @@ -103,6 +103,7 @@ int nxsem_trywait_slow(FAR sem_t *sem) /* It is, let the task take the semaphore */ +#ifdef CONFIG_PRIORITY_PROTECT ret = nxsem_protect_wait(sem); if (ret < 0) { @@ -117,6 +118,7 @@ int nxsem_trywait_slow(FAR sem_t *sem) goto out; } +#endif if (!mutex) { diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index 899263de84d..dd0ea8893dd 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -73,7 +73,7 @@ int nxsem_wait_slow(FAR sem_t *sem) { FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; - int ret; + int ret = OK; bool unlocked; FAR struct tcb_s *htcb = NULL; bool mutex = NXSEM_IS_MUTEX(sem); @@ -121,6 +121,7 @@ int nxsem_wait_slow(FAR sem_t *sem) { /* It is, let the task take the semaphore. */ +#ifdef CONFIG_PRIORITY_PROTECT ret = nxsem_protect_wait(sem); if (ret < 0) { @@ -136,6 +137,7 @@ int nxsem_wait_slow(FAR sem_t *sem) leave_critical_section(flags); return ret; } +#endif /* For mutexes, we only add the holder to the tasks list at the * time when a task blocks on the mutex, for priority restoration diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index 8d86c380922..b4ba224114d 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -102,9 +102,6 @@ void nxsem_release_all(FAR struct tcb_s *stcb); #ifdef CONFIG_PRIORITY_PROTECT int nxsem_protect_wait(FAR sem_t *sem); void nxsem_protect_post(FAR sem_t *sem); -#else -# define nxsem_protect_wait(sem) 0 -# define nxsem_protect_post(sem) #endif #undef EXTERN
