Skip to content

Commit 6913e52

Browse files
wangchdoacassis
authored andcommitted
sched/signal: Remove redundant code in nxsig_wait_irq()
nxsig_wait_irq() is always invoked within an existing critical section, and the task state is already verified, similar to nxsem_wait_irq(). Therefore, the additional critical section protection and task state check inside the function are redundant and have been removed. Signed-off-by: Chengdong Wang <[email protected]>
1 parent 6e7a498 commit 6913e52

File tree

1 file changed

+17
-43
lines changed

1 file changed

+17
-43
lines changed

sched/signal/sig_timedwait.c

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,58 +140,32 @@ static void nxsig_timeout(wdparm_t arg)
140140
#ifdef CONFIG_CANCELLATION_POINTS
141141
void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode)
142142
{
143-
#ifdef CONFIG_SMP
144-
irqstate_t flags;
143+
FAR struct tcb_s *rtcb = this_task();
145144

146-
/* We must be in a critical section in order to call up_switch_context()
147-
* below. If we are running on a single CPU architecture, then we know
148-
* interrupts a disabled an there is no need to explicitly call
149-
* enter_critical_section(). However, in the SMP case,
150-
* enter_critical_section() does much more than just disable interrupts on
151-
* the local CPU; it also manages spinlocks to assure the stability of the
152-
* TCB that we are manipulating.
153-
*/
154-
155-
flags = enter_critical_section();
156-
#endif
157-
158-
/* There may be a race condition -- make sure the task is
159-
* still waiting for a signal
160-
*/
161-
162-
if (wtcb->task_state == TSTATE_WAIT_SIG)
145+
if (wtcb->sigunbinfo != NULL)
163146
{
164-
FAR struct tcb_s *rtcb = this_task();
165-
166-
if (wtcb->sigunbinfo != NULL)
167-
{
168-
wtcb->sigunbinfo->si_signo = SIG_CANCEL_TIMEOUT;
169-
wtcb->sigunbinfo->si_code = SI_USER;
170-
wtcb->sigunbinfo->si_errno = errcode;
171-
wtcb->sigunbinfo->si_value.sival_int = 0;
147+
wtcb->sigunbinfo->si_signo = SIG_CANCEL_TIMEOUT;
148+
wtcb->sigunbinfo->si_code = SI_USER;
149+
wtcb->sigunbinfo->si_errno = errcode;
150+
wtcb->sigunbinfo->si_value.sival_int = 0;
172151
#ifdef CONFIG_SCHED_HAVE_PARENT
173-
wtcb->sigunbinfo->si_pid = 0; /* Not applicable */
174-
wtcb->sigunbinfo->si_status = OK;
152+
wtcb->sigunbinfo->si_pid = 0; /* Not applicable */
153+
wtcb->sigunbinfo->si_status = OK;
175154
#endif
176-
}
155+
}
177156

178-
/* Remove the task from waiting list */
157+
/* Remove the task from waiting list */
179158

180-
dq_rem((FAR dq_entry_t *)wtcb, list_waitingforsignal());
159+
dq_rem((FAR dq_entry_t *)wtcb, list_waitingforsignal());
181160

182-
/* Add the task to ready-to-run task list, and
183-
* perform the context switch if one is needed
184-
*/
161+
/* Add the task to ready-to-run task list, and
162+
* perform the context switch if one is needed
163+
*/
185164

186-
if (nxsched_add_readytorun(wtcb))
187-
{
188-
up_switch_context(this_task(), rtcb);
189-
}
165+
if (nxsched_add_readytorun(wtcb))
166+
{
167+
up_switch_context(this_task(), rtcb);
190168
}
191-
192-
#ifdef CONFIG_SMP
193-
leave_critical_section(flags);
194-
#endif
195169
}
196170
#endif /* CONFIG_CANCELLATION_POINTS */
197171

0 commit comments

Comments
 (0)