Skip to content

Commit c5757ed

Browse files
shtirlicxiaoxiang781216
authored andcommitted
sched/timedwait: Ensure critical section for nxsig_timeout
nxsig_timeout calls nxsched_add_readytorun and up_switch_context, so must be in critical section. nxsig_timeout is used as wdentry in nxsig_clockwait See wd_expiration CALL_FUNC is not in critical section. Signed-off-by: Serg Podtynnyi <[email protected]>
1 parent 57a7cb5 commit c5757ed

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

sched/signal/sig_timedwait.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,14 @@
7878
static void nxsig_timeout(wdparm_t arg)
7979
{
8080
FAR struct tcb_s *wtcb = (FAR struct tcb_s *)(uintptr_t)arg;
81-
#ifdef CONFIG_SMP
81+
8282
irqstate_t flags;
8383

8484
/* We must be in a critical section in order to call up_switch_context()
85-
* below. If we are running on a single CPU architecture, then we know
86-
* interrupts a disabled an there is no need to explicitly call
87-
* enter_critical_section(). However, in the SMP case,
88-
* enter_critical_section() does much more than just disable interrupts on
89-
* the local CPU; it also manages spinlocks to assure the stability of the
90-
* TCB that we are manipulating.
85+
* below.
9186
*/
9287

9388
flags = enter_critical_section();
94-
#endif
9589

9690
/* There may be a race condition -- make sure the task is
9791
* still waiting for a signal
@@ -127,9 +121,7 @@ static void nxsig_timeout(wdparm_t arg)
127121
}
128122
}
129123

130-
#ifdef CONFIG_SMP
131124
leave_critical_section(flags);
132-
#endif
133125
}
134126

135127
/****************************************************************************
@@ -252,8 +244,8 @@ int nxsig_clockwait(int clockid, int flags,
252244
FAR const struct timespec *rqtp,
253245
FAR struct timespec *rmtp)
254246
{
255-
FAR struct tcb_s *rtcb = this_task();
256-
irqstate_t iflags;
247+
FAR struct tcb_s *rtcb;
248+
irqstate_t iflags;
257249
clock_t expect = 0;
258250
clock_t stop;
259251

@@ -297,6 +289,7 @@ int nxsig_clockwait(int clockid, int flags,
297289
#endif
298290

299291
iflags = enter_critical_section();
292+
rtcb = this_task();
300293

301294
if (rqtp)
302295
{
@@ -394,7 +387,7 @@ int nxsig_clockwait(int clockid, int flags,
394387
int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
395388
FAR const struct timespec *timeout)
396389
{
397-
FAR struct tcb_s *rtcb = this_task();
390+
FAR struct tcb_s *rtcb;
398391
sigset_t intersection;
399392
FAR sigpendq_t *sigpend;
400393
irqstate_t flags;
@@ -410,6 +403,7 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
410403
*/
411404

412405
flags = enter_critical_section();
406+
rtcb = this_task();
413407

414408
/* Check if there is a pending signal corresponding to one of the
415409
* signals in the pending signal set argument.

0 commit comments

Comments
 (0)