sched/signal: Simplify the implementation of SIGEV_THREAD_TID.
This commit simplified thread ID dispatching logic by integrating it into the `nxsig_dispatch` function. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
parent
0373ba0fab
commit
db88754822
@ -600,7 +600,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info)
|
||||
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread)
|
||||
{
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
FAR struct tcb_s *stcb;
|
||||
@ -631,17 +631,30 @@ int nxsig_dispatch(pid_t pid, FAR siginfo_t *info)
|
||||
|
||||
if (group != NULL)
|
||||
{
|
||||
/* Yes.. call group_signal() to send the signal to the correct group
|
||||
* member.
|
||||
*/
|
||||
if (thread)
|
||||
{
|
||||
/* Before the notification, we should validate the tid and
|
||||
* and make sure that the notified thread is in same process
|
||||
* with the current thread.
|
||||
*/
|
||||
|
||||
return group_signal(group, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -ESRCH;
|
||||
if (stcb != NULL && group == this_task()->group)
|
||||
{
|
||||
return nxsig_tcbdispatch(stcb, info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes.. call group_signal() to send the signal to the correct
|
||||
* group member.
|
||||
*/
|
||||
|
||||
return group_signal(group, info);
|
||||
}
|
||||
}
|
||||
|
||||
return -ESRCH;
|
||||
|
||||
#else
|
||||
FAR struct tcb_s *stcb;
|
||||
|
||||
|
@ -109,7 +109,7 @@ int nxsig_kill(pid_t pid, int signo)
|
||||
|
||||
/* Send the signal */
|
||||
|
||||
return nxsig_dispatch(pid, &info);
|
||||
return nxsig_dispatch(pid, &info, false);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -112,8 +112,8 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event,
|
||||
|
||||
if (event->sigev_notify & SIGEV_SIGNAL)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
siginfo_t info;
|
||||
bool thread = false;
|
||||
|
||||
/* Yes.. Create the siginfo structure */
|
||||
|
||||
@ -121,7 +121,7 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event,
|
||||
info.si_code = code;
|
||||
info.si_errno = OK;
|
||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
||||
info.si_pid = rtcb->pid;
|
||||
info.si_pid = this_task()->pid;
|
||||
info.si_status = OK;
|
||||
#endif
|
||||
info.si_user = NULL;
|
||||
@ -134,28 +134,17 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event,
|
||||
|
||||
memcpy(&info.si_value, &event->sigev_value, sizeof(union sigval));
|
||||
|
||||
/* Used only by POSIX timer. Before the notification, we should
|
||||
* validate the tid and make sure that the notified thread is
|
||||
* in same process with current thread.
|
||||
*/
|
||||
/* SIGEV_THREAD_ID currently used only by POSIX timer. */
|
||||
|
||||
if (event->sigev_notify & SIGEV_THREAD_ID)
|
||||
{
|
||||
FAR struct tcb_s *ptcb;
|
||||
ptcb = nxsched_get_tcb(event->sigev_notify_thread_id);
|
||||
if (ptcb != NULL && ptcb->group == rtcb->group)
|
||||
{
|
||||
return nxsig_tcbdispatch(ptcb, &info);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
thread = true;
|
||||
pid = event->sigev_notify_thread_id;
|
||||
}
|
||||
|
||||
/* Send the signal */
|
||||
|
||||
return nxsig_dispatch(pid, &info);
|
||||
return nxsig_dispatch(pid, &info, thread);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SIG_EVTHREAD
|
||||
|
@ -106,7 +106,7 @@ int nxsig_queue(int pid, int signo, union sigval value)
|
||||
|
||||
/* Send the signal */
|
||||
|
||||
return nxsig_dispatch(pid, &info);
|
||||
return nxsig_dispatch(pid, &info, false);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -168,7 +168,8 @@ int nxsig_default_initialize(FAR struct tcb_s *tcb);
|
||||
|
||||
int nxsig_tcbdispatch(FAR struct tcb_s *stcb,
|
||||
FAR siginfo_t *info);
|
||||
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info);
|
||||
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info,
|
||||
bool thread);
|
||||
|
||||
/* sig_cleanup.c */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user