Deleted Added
full compact
kern_thread.c (102292) kern_thread.c (102581)
1/*
2 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 * DAMAGE.
27 *
1/*
2 * Copyright (C) 2001 Julian Elischer <julian@freebsd.org>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 * DAMAGE.
27 *
28 * $FreeBSD: head/sys/kern/kern_thread.c 102292 2002-08-22 21:45:58Z julian $
28 * $FreeBSD: head/sys/kern/kern_thread.c 102581 2002-08-29 19:49:53Z julian $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>

--- 278 unchanged lines hidden (view full) ---

315 struct ksegrp *kg;
316
317 td = curthread;
318 kg = td->td_ksegrp;
319 p = td->td_proc;
320 ke = td->td_kse;
321
322 mtx_assert(&sched_lock, MA_OWNED);
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>

--- 278 unchanged lines hidden (view full) ---

315 struct ksegrp *kg;
316
317 td = curthread;
318 kg = td->td_ksegrp;
319 p = td->td_proc;
320 ke = td->td_kse;
321
322 mtx_assert(&sched_lock, MA_OWNED);
323 KASSERT(p != NULL, ("thread exiting without a process"));
324 KASSERT(ke != NULL, ("thread exiting without a kse"));
325 KASSERT(kg != NULL, ("thread exiting without a kse group"));
323 PROC_LOCK_ASSERT(p, MA_OWNED);
324 CTR1(KTR_PROC, "thread_exit: thread %p", td);
325 KASSERT(!mtx_owned(&Giant), ("dying thread owns giant"));
326
327 if (ke->ke_tdspare != NULL) {
328 thread_stash(ke->ke_tdspare);
329 ke->ke_tdspare = NULL;
330 }
331 cpu_thread_exit(td); /* XXXSMP */
332
333 /* Reassign this thread's KSE. */
326 PROC_LOCK_ASSERT(p, MA_OWNED);
327 CTR1(KTR_PROC, "thread_exit: thread %p", td);
328 KASSERT(!mtx_owned(&Giant), ("dying thread owns giant"));
329
330 if (ke->ke_tdspare != NULL) {
331 thread_stash(ke->ke_tdspare);
332 ke->ke_tdspare = NULL;
333 }
334 cpu_thread_exit(td); /* XXXSMP */
335
336 /* Reassign this thread's KSE. */
334 if (ke != NULL) {
335 ke->ke_thread = NULL;
336 td->td_kse = NULL;
337 ke->ke_state = KES_UNQUEUED;
338 kse_reassign(ke);
339 }
337 ke->ke_thread = NULL;
338 td->td_kse = NULL;
339 ke->ke_state = KES_UNQUEUED;
340 kse_reassign(ke);
340
341 /* Unlink this thread from its proc. and the kseg */
341
342 /* Unlink this thread from its proc. and the kseg */
342 if (p != NULL) {
343 TAILQ_REMOVE(&p->p_threads, td, td_plist);
344 p->p_numthreads--;
345 if (kg != NULL) {
346 TAILQ_REMOVE(&kg->kg_threads, td, td_kglist);
347 kg->kg_numthreads--;
343 TAILQ_REMOVE(&p->p_threads, td, td_plist);
344 p->p_numthreads--;
345 TAILQ_REMOVE(&kg->kg_threads, td, td_kglist);
346 kg->kg_numthreads--;
347 /*
348 * The test below is NOT true if we are the
349 * sole exiting thread. P_STOPPED_SNGL is unset
350 * in exit1() after it is the only survivor.
351 */
352 if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) {
353 if (p->p_numthreads == p->p_suspcount) {
354 TAILQ_REMOVE(&p->p_suspended,
355 p->p_singlethread, td_runq);
356 setrunqueue(p->p_singlethread);
357 p->p_suspcount--;
348 }
358 }
349 /*
350 * The test below is NOT true if we are the
351 * sole exiting thread. P_STOPPED_SNGL is unset
352 * in exit1() after it is the only survivor.
353 */
354 if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) {
355 if (p->p_numthreads == p->p_suspcount) {
356 TAILQ_REMOVE(&p->p_suspended,
357 p->p_singlethread, td_runq);
358 setrunqueue(p->p_singlethread);
359 p->p_suspcount--;
360 }
361 }
362 }
359 }
360 PROC_UNLOCK(p);
363 td->td_state = TDS_SURPLUS;
364 td->td_proc = NULL;
365 td->td_ksegrp = NULL;
366 td->td_last_kse = NULL;
367 ke->ke_tdspare = td;
361 td->td_state = TDS_SURPLUS;
362 td->td_proc = NULL;
363 td->td_ksegrp = NULL;
364 td->td_last_kse = NULL;
365 ke->ke_tdspare = td;
368 PROC_UNLOCK(p);
369 cpu_throw();
370 /* NOTREACHED */
371}
372
373/*
374 * Link a thread to a process.
375 *
376 * Note that we do not link to the proc's ucred here.

--- 448 unchanged lines hidden ---
366 cpu_throw();
367 /* NOTREACHED */
368}
369
370/*
371 * Link a thread to a process.
372 *
373 * Note that we do not link to the proc's ucred here.

--- 448 unchanged lines hidden ---