Skip to content

Commit 201406b

Browse files
wangchdoacassis
authored andcommitted
sched/sched: Reuse nxsig_wait_irq() in nxsig_timeout()
Currently, there is duplicated code in nxsig_wait_irq() and nxsig_timeout(). This patch updates the input parameters of nxsig_wait_irq() so that it can be reused in nxsig_timeout(), reducing code duplication and improving maintainability. Signed-off-by: Chengdong Wang <[email protected]>
1 parent 6913e52 commit 201406b

File tree

3 files changed

+18
-45
lines changed

3 files changed

+18
-45
lines changed

sched/signal/sig_timedwait.c

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@
5151
* Pre-processor Definitions
5252
****************************************************************************/
5353

54-
/* These are special values of si_signo that mean that either the wait was
55-
* awakened with a timeout, or the wait was canceled... not the receipt of a
56-
* signal.
57-
*/
58-
59-
#define SIG_CANCEL_TIMEOUT 0xfe
60-
#define SIG_WAIT_TIMEOUT 0xff
61-
6254
/****************************************************************************
6355
* Private Functions
6456
****************************************************************************/
@@ -93,32 +85,7 @@ static void nxsig_timeout(wdparm_t arg)
9385

9486
if (wtcb->task_state == TSTATE_WAIT_SIG)
9587
{
96-
FAR struct tcb_s *rtcb = this_task();
97-
98-
if (wtcb->sigunbinfo != NULL)
99-
{
100-
wtcb->sigunbinfo->si_signo = SIG_WAIT_TIMEOUT;
101-
wtcb->sigunbinfo->si_code = SI_TIMER;
102-
wtcb->sigunbinfo->si_errno = ETIMEDOUT;
103-
wtcb->sigunbinfo->si_value.sival_int = 0;
104-
#ifdef CONFIG_SCHED_HAVE_PARENT
105-
wtcb->sigunbinfo->si_pid = 0; /* Not applicable */
106-
wtcb->sigunbinfo->si_status = OK;
107-
#endif
108-
}
109-
110-
/* Remove the task from waiting list */
111-
112-
dq_rem((FAR dq_entry_t *)wtcb, list_waitingforsignal());
113-
114-
/* Add the task to ready-to-run task list, and
115-
* perform the context switch if one is needed
116-
*/
117-
118-
if (nxsched_add_readytorun(wtcb))
119-
{
120-
up_switch_context(this_task(), rtcb);
121-
}
88+
nxsig_wait_irq(wtcb, SIG_WAIT_TIMEOUT, SI_TIMER, ETIMEDOUT);
12289
}
12390

12491
leave_critical_section(flags);
@@ -137,15 +104,15 @@ static void nxsig_timeout(wdparm_t arg)
137104
*
138105
****************************************************************************/
139106

140-
#ifdef CONFIG_CANCELLATION_POINTS
141-
void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode)
107+
void nxsig_wait_irq(FAR struct tcb_s *wtcb, uint8_t signo,
108+
uint8_t code, int errcode)
142109
{
143110
FAR struct tcb_s *rtcb = this_task();
144111

145112
if (wtcb->sigunbinfo != NULL)
146113
{
147-
wtcb->sigunbinfo->si_signo = SIG_CANCEL_TIMEOUT;
148-
wtcb->sigunbinfo->si_code = SI_USER;
114+
wtcb->sigunbinfo->si_signo = signo;
115+
wtcb->sigunbinfo->si_code = code;
149116
wtcb->sigunbinfo->si_errno = errcode;
150117
wtcb->sigunbinfo->si_value.sival_int = 0;
151118
#ifdef CONFIG_SCHED_HAVE_PARENT
@@ -159,15 +126,14 @@ void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode)
159126
dq_rem((FAR dq_entry_t *)wtcb, list_waitingforsignal());
160127

161128
/* Add the task to ready-to-run task list, and
162-
* perform the context switch if one is needed
163-
*/
129+
* perform the context switch if one is needed
130+
*/
164131

165132
if (nxsched_add_readytorun(wtcb))
166133
{
167134
up_switch_context(this_task(), rtcb);
168135
}
169136
}
170-
#endif /* CONFIG_CANCELLATION_POINTS */
171137

172138
/****************************************************************************
173139
* Name: nxsig_clockwait

sched/signal/signal.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
* Pre-processor Definitions
4242
****************************************************************************/
4343

44+
/* These are special values of si_signo that mean that either the wait was
45+
* awakened with a timeout, or the wait was canceled... not the receipt of a
46+
* signal.
47+
*/
48+
49+
#define SIG_CANCEL_TIMEOUT 0xfe
50+
#define SIG_WAIT_TIMEOUT 0xff
51+
4452
/* The following definition determines the number of signal structures to
4553
* allocate in a block
4654
*/
@@ -181,9 +189,8 @@ void nxsig_release(FAR struct task_group_s *group);
181189

182190
/* sig_timedwait.c */
183191

184-
#ifdef CONFIG_CANCELLATION_POINTS
185-
void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode);
186-
#endif
192+
void nxsig_wait_irq(FAR struct tcb_s *wtcb, uint8_t signo,
193+
uint8_t code, int errcode);
187194

188195
/* In files of the same name */
189196

sched/task/task_cancelpt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ bool nxnotify_cancellation(FAR struct tcb_s *tcb)
162162

163163
else if (tcb->task_state == TSTATE_WAIT_SIG)
164164
{
165-
nxsig_wait_irq(tcb, ECANCELED);
165+
nxsig_wait_irq(tcb, SIG_CANCEL_TIMEOUT, SI_USER, ECANCELED);
166166
}
167167

168168
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)

0 commit comments

Comments
 (0)