MCPcopy Create free account
hub / github.com/F-Stack/f-stack / thread_exit

Function thread_exit

freebsd/kern/kern_thread.c:848–955  ·  view source on GitHub ↗

* Discard the current thread and exit from its context. * Always called with scheduler locked. * * Because we can't free a thread while we're operating under its context, * push the current thread into our CPU's deadthread holder. This means * we needn't worry about someone else grabbing our context before we * do a cpu_throw(). */

Source from the content-addressed store, hash-verified

846 * do a cpu_throw().
847 */
848void
849thread_exit(void)
850{
851 uint64_t runtime, new_switchtime;
852 struct thread *td;
853 struct thread *td2;
854 struct proc *p;
855 int wakeup_swapper;
856
857 td = curthread;
858 p = td->td_proc;
859
860 PROC_SLOCK_ASSERT(p, MA_OWNED);
861 mtx_assert(&Giant, MA_NOTOWNED);
862
863 PROC_LOCK_ASSERT(p, MA_OWNED);
864 KASSERT(p != NULL, ("thread exiting without a process"));
865 CTR3(KTR_PROC, "thread_exit: thread %p (pid %ld, %s)", td,
866 (long)p->p_pid, td->td_name);
867 SDT_PROBE0(proc, , , lwp__exit);
868 KASSERT(TAILQ_EMPTY(&td->td_sigqueue.sq_list), ("signal pending"));
869 MPASS(td->td_realucred == td->td_ucred);
870
871 /*
872 * drop FPU & debug register state storage, or any other
873 * architecture specific resources that
874 * would not be on a new untouched process.
875 */
876 cpu_thread_exit(td);
877
878 /*
879 * The last thread is left attached to the process
880 * So that the whole bundle gets recycled. Skip
881 * all this stuff if we never had threads.
882 * EXIT clears all sign of other threads when
883 * it goes to single threading, so the last thread always
884 * takes the short path.
885 */
886 if (p->p_flag & P_HADTHREADS) {
887 if (p->p_numthreads > 1) {
888 atomic_add_int(&td->td_proc->p_exitthreads, 1);
889 thread_unlink(td);
890 td2 = FIRST_THREAD_IN_PROC(p);
891 sched_exit_thread(td2, td);
892
893 /*
894 * The test below is NOT true if we are the
895 * sole exiting thread. P_STOPPED_SINGLE is unset
896 * in exit1() after it is the only survivor.
897 */
898 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
899 if (p->p_numthreads == p->p_suspcount) {
900 thread_lock(p->p_singlethread);
901 wakeup_swapper = thread_unsuspend_one(
902 p->p_singlethread, p, false);
903 if (wakeup_swapper)
904 kick_proc0();
905 }

Callers 15

vdev_rebuild_threadFunction · 0.85
mmp_thread_exitFunction · 0.85
vdev_initialize_threadFunction · 0.85
txg_thread_exitFunction · 0.85
vdev_trim_threadFunction · 0.85
vdev_autotrim_threadFunction · 0.85
vdev_trim_l2arc_threadFunction · 0.85
receive_writer_threadFunction · 0.85
l2arc_feed_threadFunction · 0.85
l2arc_dev_rebuild_threadFunction · 0.85
dbuf_evict_threadFunction · 0.85
spa_async_threadFunction · 0.85

Calls 11

mtx_assertFunction · 0.85
thread_unlinkFunction · 0.85
thread_unsuspend_oneFunction · 0.85
kick_proc0Function · 0.85
ruxagg_lockedFunction · 0.85
rucollectFunction · 0.85
witness_thread_exitFunction · 0.85
sched_exit_threadFunction · 0.70
panicFunction · 0.70
sched_throwFunction · 0.70
cpu_thread_exitFunction · 0.50

Tested by 4

sweep_threadFunction · 0.68
ztest_resume_threadFunction · 0.68
ztest_deadman_threadFunction · 0.68
ztest_threadFunction · 0.68