This is an automated email from the ASF dual-hosted git repository. archer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit db887548227b208746e3e3e59fbc51a9aaf0745f Author: ouyangxiangzhen <[email protected]> AuthorDate: Thu Sep 19 10:43:59 2024 +0800 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 <[email protected]> --- sched/signal/sig_dispatch.c | 31 ++++++++++++++++++++++--------- sched/signal/sig_kill.c | 2 +- sched/signal/sig_notification.c | 23 ++++++----------------- sched/signal/sig_queue.c | 2 +- sched/signal/signal.h | 3 ++- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index d69fa046fa..7e238b8e95 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -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; diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 471beae977..c3840e3a6c 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -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); } /**************************************************************************** diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c index b102da7839..8f96260390 100644 --- a/sched/signal/sig_notification.c +++ b/sched/signal/sig_notification.c @@ -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 diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index acea7b590f..cc0589e611 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -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); } /**************************************************************************** diff --git a/sched/signal/signal.h b/sched/signal/signal.h index c4d88e1442..7fef91d116 100644 --- a/sched/signal/signal.h +++ b/sched/signal/signal.h @@ -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 */
