mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
committed by
Alan C. Assis
parent
e23f2546c3
commit
922426346e
@@ -246,7 +246,9 @@ int nxsem_post_slow(FAR sem_t *sem)
|
|||||||
}
|
}
|
||||||
else if (proto == SEM_PRIO_PROTECT)
|
else if (proto == SEM_PRIO_PROTECT)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_PRIORITY_PROTECT
|
||||||
nxsem_protect_post(sem);
|
nxsem_protect_post(sem);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
int nxsem_trywait_slow(FAR sem_t *sem)
|
int nxsem_trywait_slow(FAR sem_t *sem)
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int ret = -EAGAIN;
|
int ret = OK;
|
||||||
bool mutex = NXSEM_IS_MUTEX(sem);
|
bool mutex = NXSEM_IS_MUTEX(sem);
|
||||||
FAR atomic_t *val = mutex ? NXSEM_MHOLDER(sem) : NXSEM_COUNT(sem);
|
FAR atomic_t *val = mutex ? NXSEM_MHOLDER(sem) : NXSEM_COUNT(sem);
|
||||||
int32_t old;
|
int32_t old;
|
||||||
@@ -103,6 +103,7 @@ int nxsem_trywait_slow(FAR sem_t *sem)
|
|||||||
|
|
||||||
/* It is, let the task take the semaphore */
|
/* It is, let the task take the semaphore */
|
||||||
|
|
||||||
|
#ifdef CONFIG_PRIORITY_PROTECT
|
||||||
ret = nxsem_protect_wait(sem);
|
ret = nxsem_protect_wait(sem);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@@ -117,6 +118,7 @@ int nxsem_trywait_slow(FAR sem_t *sem)
|
|||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!mutex)
|
if (!mutex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int nxsem_wait_slow(FAR sem_t *sem)
|
|||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
int ret;
|
int ret = OK;
|
||||||
bool unlocked;
|
bool unlocked;
|
||||||
FAR struct tcb_s *htcb = NULL;
|
FAR struct tcb_s *htcb = NULL;
|
||||||
bool mutex = NXSEM_IS_MUTEX(sem);
|
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. */
|
/* It is, let the task take the semaphore. */
|
||||||
|
|
||||||
|
#ifdef CONFIG_PRIORITY_PROTECT
|
||||||
ret = nxsem_protect_wait(sem);
|
ret = nxsem_protect_wait(sem);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@@ -136,6 +137,7 @@ int nxsem_wait_slow(FAR sem_t *sem)
|
|||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* For mutexes, we only add the holder to the tasks list at the
|
/* For mutexes, we only add the holder to the tasks list at the
|
||||||
* time when a task blocks on the mutex, for priority restoration
|
* time when a task blocks on the mutex, for priority restoration
|
||||||
|
|||||||
@@ -102,9 +102,6 @@ void nxsem_release_all(FAR struct tcb_s *stcb);
|
|||||||
#ifdef CONFIG_PRIORITY_PROTECT
|
#ifdef CONFIG_PRIORITY_PROTECT
|
||||||
int nxsem_protect_wait(FAR sem_t *sem);
|
int nxsem_protect_wait(FAR sem_t *sem);
|
||||||
void nxsem_protect_post(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
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
|||||||
Reference in New Issue
Block a user