sched: pthread: Remove a redundant critical section in pthread_condclockwsait.c
Summary: - This commit removes a redundant critical section in pthread_condclockwait.c Impact: - None Testing: - Tested with ostest with the following configs - maix-bit:smp, esp32-devkitc:smp, sabre-6quad:smp - spresense:smp, sim:smp - maix-bit:nsh, sabre-6quad:nsh - sprsesnse:wifi, sim:ostest - Tested with nxplayer with the folowing configs - spresense:wifi_smp, spresense:rndis_smp Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
parent
9eca886f26
commit
2976bb212e
@ -154,7 +154,6 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
FAR const struct timespec *abstime)
|
FAR const struct timespec *abstime)
|
||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
irqstate_t flags;
|
|
||||||
sclock_t ticks;
|
sclock_t ticks;
|
||||||
int mypid = getpid();
|
int mypid = getpid();
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
@ -193,14 +192,15 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
{
|
{
|
||||||
sinfo("Give up mutex...\n");
|
sinfo("Give up mutex...\n");
|
||||||
|
|
||||||
/* We must disable pre-emption and interrupts here so that
|
/* NOTE: We do not need a critical section here,
|
||||||
* the time stays valid until the wait begins. This adds
|
* because nxsem_wait() uses a critical section and
|
||||||
* complexity because we assure that interrupts and
|
* pthread_condtimedout() is called from wd_timer()
|
||||||
* pre-emption are re-enabled correctly.
|
* which uses a critical section for SMP case
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* REVISIT: Do we need to disable pre-emption? */
|
||||||
|
|
||||||
sched_lock();
|
sched_lock();
|
||||||
flags = enter_critical_section();
|
|
||||||
|
|
||||||
/* Convert the timespec to clock ticks. We must disable pre-
|
/* Convert the timespec to clock ticks. We must disable pre-
|
||||||
* emption here so that this time stays valid until the wait
|
* emption here so that this time stays valid until the wait
|
||||||
@ -208,15 +208,7 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ret = clock_abstime2ticks(clockid, abstime, &ticks);
|
ret = clock_abstime2ticks(clockid, abstime, &ticks);
|
||||||
if (ret)
|
if (ret == 0)
|
||||||
{
|
|
||||||
/* Restore interrupts (pre-emption will be enabled when
|
|
||||||
* we fall through the if/then/else)
|
|
||||||
*/
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
/* Check the absolute time to wait. If it is now or in the
|
/* Check the absolute time to wait. If it is now or in the
|
||||||
* past, then just return with the timedout condition.
|
* past, then just return with the timedout condition.
|
||||||
@ -224,12 +216,6 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
|
|
||||||
if (ticks <= 0)
|
if (ticks <= 0)
|
||||||
{
|
{
|
||||||
/* Restore interrupts and indicate that we have already
|
|
||||||
* timed out. (pre-emption will be enabled when we fall
|
|
||||||
* through the if/then/else
|
|
||||||
*/
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
ret = ETIMEDOUT;
|
ret = ETIMEDOUT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -252,15 +238,7 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
nlocks = mutex->nlocks;
|
nlocks = mutex->nlocks;
|
||||||
#endif
|
#endif
|
||||||
ret = pthread_mutex_give(mutex);
|
ret = pthread_mutex_give(mutex);
|
||||||
if (ret != 0)
|
if (ret == 0)
|
||||||
{
|
|
||||||
/* Restore interrupts (pre-emption will be enabled
|
|
||||||
* when we fall through the if/then/else)
|
|
||||||
*/
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
/* Start the watchdog */
|
/* Start the watchdog */
|
||||||
|
|
||||||
@ -299,14 +277,6 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
ret = status;
|
ret = status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The interrupts stay disabled until after we sample
|
|
||||||
* the errno. This is because when debug is enabled
|
|
||||||
* and the console is used for debug output, then the
|
|
||||||
* errno can be altered by interrupt handling! (bad)
|
|
||||||
*/
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reacquire the mutex (retaining the ret). */
|
/* Reacquire the mutex (retaining the ret). */
|
||||||
@ -332,9 +302,7 @@ int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Re-enable pre-emption (It is expected that interrupts
|
/* Re-enable pre-emption */
|
||||||
* have already been re-enabled in the above logic)
|
|
||||||
*/
|
|
||||||
|
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user