Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_thread.c
Show First 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | |||||
* Prepare a thread for use. | * Prepare a thread for use. | ||||
*/ | */ | ||||
static int | static int | ||||
thread_ctor(void *mem, int size, void *arg, int flags) | thread_ctor(void *mem, int size, void *arg, int flags) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
td = (struct thread *)mem; | td = (struct thread *)mem; | ||||
td->td_state = TDS_INACTIVE; | TD_SET_STATE(td, TDS_INACTIVE); | ||||
td->td_lastcpu = td->td_oncpu = NOCPU; | td->td_lastcpu = td->td_oncpu = NOCPU; | ||||
/* | /* | ||||
* Note that td_critnest begins life as 1 because the thread is not | * Note that td_critnest begins life as 1 because the thread is not | ||||
* running and is thereby implicitly waiting to be on the receiving | * running and is thereby implicitly waiting to be on the receiving | ||||
* end of a context switch. | * end of a context switch. | ||||
*/ | */ | ||||
td->td_critnest = 1; | td->td_critnest = 1; | ||||
Show All 16 Lines | |||||
thread_dtor(void *mem, int size, void *arg) | thread_dtor(void *mem, int size, void *arg) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
td = (struct thread *)mem; | td = (struct thread *)mem; | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
/* Verify that this thread is in a safe state to free. */ | /* Verify that this thread is in a safe state to free. */ | ||||
switch (td->td_state) { | switch (TD_GET_STATE(td)) { | ||||
case TDS_INHIBITED: | case TDS_INHIBITED: | ||||
case TDS_RUNNING: | case TDS_RUNNING: | ||||
case TDS_CAN_RUN: | case TDS_CAN_RUN: | ||||
case TDS_RUNQ: | case TDS_RUNQ: | ||||
/* | /* | ||||
* We must never unlink a thread that is in one of | * We must never unlink a thread that is in one of | ||||
* these states, because it is currently active. | * these states, because it is currently active. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 548 Lines • ▼ Show 20 Lines | #endif | ||||
VM_CNT_INC(v_swtch); | VM_CNT_INC(v_swtch); | ||||
/* Save our resource usage in our process. */ | /* Save our resource usage in our process. */ | ||||
td->td_ru.ru_nvcsw++; | td->td_ru.ru_nvcsw++; | ||||
ruxagg_locked(p, td); | ruxagg_locked(p, td); | ||||
rucollect(&p->p_ru, &td->td_ru); | rucollect(&p->p_ru, &td->td_ru); | ||||
PROC_STATUNLOCK(p); | PROC_STATUNLOCK(p); | ||||
td->td_state = TDS_INACTIVE; | TD_SET_STATE(td, TDS_INACTIVE); | ||||
#ifdef WITNESS | #ifdef WITNESS | ||||
witness_thread_exit(td); | witness_thread_exit(td); | ||||
#endif | #endif | ||||
CTR1(KTR_PROC, "thread_exit: cpu_throw() thread %p", td); | CTR1(KTR_PROC, "thread_exit: cpu_throw() thread %p", td); | ||||
sched_throw(td); | sched_throw(td); | ||||
panic("I'm a teapot!"); | panic("I'm a teapot!"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
Show All 32 Lines | |||||
thread_link(struct thread *td, struct proc *p) | thread_link(struct thread *td, struct proc *p) | ||||
{ | { | ||||
/* | /* | ||||
* XXX This can't be enabled because it's called for proc0 before | * XXX This can't be enabled because it's called for proc0 before | ||||
* its lock has been created. | * its lock has been created. | ||||
* PROC_LOCK_ASSERT(p, MA_OWNED); | * PROC_LOCK_ASSERT(p, MA_OWNED); | ||||
*/ | */ | ||||
td->td_state = TDS_INACTIVE; | TD_SET_STATE(td, TDS_INACTIVE); | ||||
td->td_proc = p; | td->td_proc = p; | ||||
td->td_flags = TDF_INMEM; | td->td_flags = TDF_INMEM; | ||||
LIST_INIT(&td->td_contested); | LIST_INIT(&td->td_contested); | ||||
LIST_INIT(&td->td_lprof[0]); | LIST_INIT(&td->td_lprof[0]); | ||||
LIST_INIT(&td->td_lprof[1]); | LIST_INIT(&td->td_lprof[1]); | ||||
#ifdef EPOCH_TRACE | #ifdef EPOCH_TRACE | ||||
SLIST_INIT(&td->td_epochs); | SLIST_INIT(&td->td_epochs); | ||||
▲ Show 20 Lines • Show All 704 Lines • Show Last 20 Lines |