mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
sched/signal/sig_dispatch.c: Simplify the nxsig_dispatch
The nxsig_dispatch should just deliver the signal to either a thread by pid (tid) or to the process (group) by pid. Simplify the code so that the intent is more obvious. Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
committed by
Xiang Xiao
parent
a4c42e54f7
commit
9413b6f331
+13
-54
@@ -725,70 +725,29 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info,
|
|||||||
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread)
|
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
#ifdef HAVE_GROUP_MEMBERS
|
||||||
FAR struct tcb_s *stcb;
|
if (!thread)
|
||||||
FAR struct task_group_s *group;
|
|
||||||
|
|
||||||
/* Get the TCB associated with the pid */
|
|
||||||
|
|
||||||
stcb = nxsched_get_tcb(pid);
|
|
||||||
if (stcb != NULL)
|
|
||||||
{
|
{
|
||||||
/* The task/thread associated with this PID is still active. Get its
|
/* Find the group by process PID and call group signal() to send the
|
||||||
* task group.
|
* signal to the correct group member.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
group = stcb->group;
|
FAR struct task_group_s *group = task_getgroup(pid);
|
||||||
|
if (group != NULL)
|
||||||
|
{
|
||||||
|
return group_signal(group, info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
/* The task/thread associated with this PID has exited. In the normal
|
/* Get the TCB associated with the thread TID */
|
||||||
* usage model, the PID should correspond to the PID of the task that
|
|
||||||
* created the task group. Try looking it up.
|
|
||||||
*/
|
|
||||||
|
|
||||||
group = task_getgroup(pid);
|
FAR struct tcb_s *stcb = nxsched_get_tcb(pid);
|
||||||
}
|
if (stcb != NULL)
|
||||||
|
|
||||||
/* Did we locate the group? */
|
|
||||||
|
|
||||||
if (group != NULL)
|
|
||||||
{
|
|
||||||
if (thread)
|
|
||||||
{
|
{
|
||||||
/* Before the notification, we should validate the tid. If the
|
return nxsig_tcbdispatch(stcb, info, false);
|
||||||
* signal is to be delivered to a thread which has exited, it is
|
|
||||||
* just dropped.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (stcb != NULL)
|
|
||||||
{
|
|
||||||
return nxsig_tcbdispatch(stcb, info, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Yes.. call group_signal() to send the signal to the correct
|
|
||||||
* group member.
|
|
||||||
*/
|
|
||||||
|
|
||||||
return group_signal(group, info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
|
||||||
#else
|
|
||||||
FAR struct tcb_s *stcb;
|
|
||||||
|
|
||||||
/* Get the TCB associated with the pid */
|
|
||||||
|
|
||||||
stcb = nxsched_get_tcb(pid);
|
|
||||||
if (stcb == NULL)
|
|
||||||
{
|
|
||||||
return -ESRCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nxsig_tcbdispatch(stcb, info, false);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user