Skip to content

Commit a030e3c

Browse files
jlaitineanchao
authored andcommitted
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>
1 parent a0caa5c commit a030e3c

File tree

1 file changed

+13
-54
lines changed

1 file changed

+13
-54
lines changed

sched/signal/sig_dispatch.c

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -725,70 +725,29 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info,
725725
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread)
726726
{
727727
#ifdef HAVE_GROUP_MEMBERS
728-
FAR struct tcb_s *stcb;
729-
FAR struct task_group_s *group;
730-
731-
/* Get the TCB associated with the pid */
732-
733-
stcb = nxsched_get_tcb(pid);
734-
if (stcb != NULL)
728+
if (!thread)
735729
{
736-
/* The task/thread associated with this PID is still active. Get its
737-
* task group.
730+
/* Find the group by process PID and call group signal() to send the
731+
* signal to the correct group member.
738732
*/
739733

740-
group = stcb->group;
734+
FAR struct task_group_s *group = task_getgroup(pid);
735+
if (group != NULL)
736+
{
737+
return group_signal(group, info);
738+
}
741739
}
742740
else
741+
#endif
743742
{
744-
/* The task/thread associated with this PID has exited. In the normal
745-
* usage model, the PID should correspond to the PID of the task that
746-
* created the task group. Try looking it up.
747-
*/
748-
749-
group = task_getgroup(pid);
750-
}
751-
752-
/* Did we locate the group? */
753-
754-
if (group != NULL)
755-
{
756-
if (thread)
757-
{
758-
/* Before the notification, we should validate the tid. If the
759-
* signal is to be delivered to a thread which has exited, it is
760-
* just dropped.
761-
*/
743+
/* Get the TCB associated with the thread TID */
762744

763-
if (stcb != NULL)
764-
{
765-
return nxsig_tcbdispatch(stcb, info, false);
766-
}
767-
}
768-
else
745+
FAR struct tcb_s *stcb = nxsched_get_tcb(pid);
746+
if (stcb != NULL)
769747
{
770-
/* Yes.. call group_signal() to send the signal to the correct
771-
* group member.
772-
*/
773-
774-
return group_signal(group, info);
748+
return nxsig_tcbdispatch(stcb, info, false);
775749
}
776750
}
777751

778752
return -ESRCH;
779-
780-
#else
781-
FAR struct tcb_s *stcb;
782-
783-
/* Get the TCB associated with the pid */
784-
785-
stcb = nxsched_get_tcb(pid);
786-
if (stcb == NULL)
787-
{
788-
return -ESRCH;
789-
}
790-
791-
return nxsig_tcbdispatch(stcb, info, false);
792-
793-
#endif
794753
}

0 commit comments

Comments
 (0)