MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _stop_thread_locked

Function _stop_thread_locked

components/lwp/lwp_signal.c:593–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591
592static int _do_signal_wakeup(rt_thread_t thread, int sig);
593static rt_err_t _stop_thread_locked(rt_lwp_t self_lwp, rt_thread_t cur_thr, int signo,
594 lwp_siginfo_t si, lwp_sigqueue_t sq)
595{
596 rt_err_t error;
597 int jobctl_stopped = self_lwp->jobctl_stopped;
598 rt_thread_t iter;
599
600 /* race to setup jobctl stopped flags */
601 if (!jobctl_stopped)
602 {
603 self_lwp->jobctl_stopped = RT_TRUE;
604 self_lwp->wait_reap_stp = RT_FALSE;
605 rt_list_for_each_entry(iter, &self_lwp->t_grp, sibling)
606 {
607 if (iter != cur_thr)
608 _do_signal_wakeup(iter, signo);
609 }
610 }
611
612 /**
613 * raise the event again so siblings is able to catch it again.
614 * `si` will be discarded while SIGCONT is generatd
615 */
616 sigqueue_enqueue(sq, si);
617
618 /* release the lwp lock so we can happily suspend */
619 LWP_UNLOCK(self_lwp);
620
621 rt_set_errno(RT_EOK);
622
623 /* After suspension, only the SIGKILL and SIGCONT will wake this thread up */
624 error = rt_thread_suspend_with_flag(cur_thr, RT_KILLABLE);
625 if (error == RT_EOK)
626 {
627 rt_schedule();
628 error = rt_get_errno();
629 error = error > 0 ? -error : error;
630 }
631
632 if (!jobctl_stopped &&
633 (sigqueue_ismember(_SIGQ(self_lwp), SIGCONT) ||
634 sigqueue_ismember(_SIGQ(cur_thr), SIGCONT)))
635 {
636 /**
637 * if we are resumed by a SIGCONT and we are the winner of racing
638 * notify parent of the incoming event
639 */
640 _notify_parent_and_leader(self_lwp, cur_thr, SIGCONT, RT_FALSE);
641 }
642
643 /* reacquire the lock since we release it before */
644 LWP_LOCK(self_lwp);
645
646 return error;
647}
648
649static void _catch_signal_locked(rt_lwp_t lwp, rt_thread_t thread, int signo,
650 lwp_siginfo_t siginfo, lwp_sighandler_t handler,

Callers 1

lwp_thread_signal_catchFunction · 0.85

Calls 8

_do_signal_wakeupFunction · 0.85
sigqueue_enqueueFunction · 0.85
rt_set_errnoFunction · 0.85
rt_get_errnoFunction · 0.85
sigqueue_ismemberFunction · 0.85
rt_scheduleFunction · 0.50

Tested by

no test coverage detected