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 <p-gaoxiang43@xiaomi.com>
This commit is contained in:
p-gaoxiang43
2025-08-04 20:33:22 +08:00
committed by Alan C. Assis
parent e23f2546c3
commit 922426346e
4 changed files with 8 additions and 5 deletions
+2
View File
@@ -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();
+3 -1
View File
@@ -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)
{
+3 -1
View File
@@ -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
-3
View File
@@ -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