Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_thread.c
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
static struct rwlock *tidhashtbl_lock; | static struct rwlock *tidhashtbl_lock; | ||||
#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash]) | #define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash]) | ||||
#define TIDHASHLOCK(tid) (&tidhashtbl_lock[(tid) & tidhashlock]) | #define TIDHASHLOCK(tid) (&tidhashtbl_lock[(tid) & tidhashlock]) | ||||
EVENTHANDLER_LIST_DEFINE(thread_ctor); | EVENTHANDLER_LIST_DEFINE(thread_ctor); | ||||
EVENTHANDLER_LIST_DEFINE(thread_dtor); | EVENTHANDLER_LIST_DEFINE(thread_dtor); | ||||
EVENTHANDLER_LIST_DEFINE(thread_init); | EVENTHANDLER_LIST_DEFINE(thread_init); | ||||
EVENTHANDLER_LIST_DEFINE(thread_fini); | EVENTHANDLER_LIST_DEFINE(thread_fini); | ||||
STATIC_EVENTHANDLER_DEFINE(thread_ctor); | |||||
STATIC_EVENTHANDLER_DEFINE(thread_dtor); | |||||
STATIC_EVENTHANDLER_DEFINE(thread_init); | |||||
STATIC_EVENTHANDLER_DEFINE(thread_fini); | |||||
static bool | static bool | ||||
thread_count_inc_try(void) | thread_count_inc_try(void) | ||||
{ | { | ||||
int nthreads_new; | int nthreads_new; | ||||
nthreads_new = atomic_fetchadd_int(&nthreads, 1) + 1; | nthreads_new = atomic_fetchadd_int(&nthreads, 1) + 1; | ||||
if (nthreads_new >= maxthread - 100) { | if (nthreads_new >= maxthread - 100) { | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | thread_init(void *mem, int size, int flags) | ||||
struct thread *td; | struct thread *td; | ||||
td = (struct thread *)mem; | td = (struct thread *)mem; | ||||
td->td_sleepqueue = sleepq_alloc(); | td->td_sleepqueue = sleepq_alloc(); | ||||
td->td_turnstile = turnstile_alloc(); | td->td_turnstile = turnstile_alloc(); | ||||
td->td_rlqe = NULL; | td->td_rlqe = NULL; | ||||
EVENTHANDLER_DIRECT_INVOKE(thread_init, td); | EVENTHANDLER_DIRECT_INVOKE(thread_init, td); | ||||
STATIC_EVENTHANDLER_INVOKE(thread_init, td); | |||||
umtx_thread_init(td); | umtx_thread_init(td); | ||||
td->td_kstack = 0; | td->td_kstack = 0; | ||||
td->td_sel = NULL; | td->td_sel = NULL; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Tear down type-stable parts of a thread (just before being discarded). | * Tear down type-stable parts of a thread (just before being discarded). | ||||
*/ | */ | ||||
static void | static void | ||||
thread_fini(void *mem, int size) | thread_fini(void *mem, int size) | ||||
{ | { | ||||
struct thread *td; | struct thread *td; | ||||
td = (struct thread *)mem; | td = (struct thread *)mem; | ||||
EVENTHANDLER_DIRECT_INVOKE(thread_fini, td); | EVENTHANDLER_DIRECT_INVOKE(thread_fini, td); | ||||
STATIC_EVENTHANDLER_INVOKE(thread_fini, td); | |||||
rlqentry_free(td->td_rlqe); | rlqentry_free(td->td_rlqe); | ||||
turnstile_free(td->td_turnstile); | turnstile_free(td->td_turnstile); | ||||
sleepq_free(td->td_sleepqueue); | sleepq_free(td->td_sleepqueue); | ||||
umtx_thread_fini(td); | umtx_thread_fini(td); | ||||
MPASS(td->td_sel == NULL); | MPASS(td->td_sel == NULL); | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | thread_reap_domain(struct thread_domain_data *tdd) | ||||
credbatch_prep(&credbatch); | credbatch_prep(&credbatch); | ||||
tdcount = 0; | tdcount = 0; | ||||
lim = NULL; | lim = NULL; | ||||
limcount = 0; | limcount = 0; | ||||
while (itd != NULL) { | while (itd != NULL) { | ||||
ntd = itd->td_zombie; | ntd = itd->td_zombie; | ||||
EVENTHANDLER_DIRECT_INVOKE(thread_dtor, itd); | EVENTHANDLER_DIRECT_INVOKE(thread_dtor, itd); | ||||
STATIC_EVENTHANDLER_INVOKE(thread_dtor, itd); | |||||
tidbatch_add(&tidbatch, itd); | tidbatch_add(&tidbatch, itd); | ||||
credbatch_add(&credbatch, itd); | credbatch_add(&credbatch, itd); | ||||
MPASS(itd->td_limit != NULL); | MPASS(itd->td_limit != NULL); | ||||
if (lim != itd->td_limit) { | if (lim != itd->td_limit) { | ||||
if (limcount != 0) { | if (limcount != 0) { | ||||
lim_freen(lim, limcount); | lim_freen(lim, limcount); | ||||
limcount = 0; | limcount = 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | if (!vm_thread_new(td, pages)) { | ||||
uma_zfree(thread_zone, td); | uma_zfree(thread_zone, td); | ||||
tid_free(tid); | tid_free(tid); | ||||
thread_count_dec(); | thread_count_dec(); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
td->td_tid = tid; | td->td_tid = tid; | ||||
cpu_thread_alloc(td); | cpu_thread_alloc(td); | ||||
EVENTHANDLER_DIRECT_INVOKE(thread_ctor, td); | EVENTHANDLER_DIRECT_INVOKE(thread_ctor, td); | ||||
STATIC_EVENTHANDLER_INVOKE(thread_ctor, td); | |||||
return (td); | return (td); | ||||
} | } | ||||
int | int | ||||
thread_alloc_stack(struct thread *td, int pages) | thread_alloc_stack(struct thread *td, int pages) | ||||
{ | { | ||||
KASSERT(td->td_kstack == 0, | KASSERT(td->td_kstack == 0, | ||||
Show All 27 Lines | |||||
} | } | ||||
void | void | ||||
thread_free(struct thread *td) | thread_free(struct thread *td) | ||||
{ | { | ||||
lwpid_t tid; | lwpid_t tid; | ||||
EVENTHANDLER_DIRECT_INVOKE(thread_dtor, td); | EVENTHANDLER_DIRECT_INVOKE(thread_dtor, td); | ||||
STATIC_EVENTHANDLER_INVOKE(thread_dtor, td); | |||||
tid = td->td_tid; | tid = td->td_tid; | ||||
thread_free_batched(td); | thread_free_batched(td); | ||||
tid_free(tid); | tid_free(tid); | ||||
thread_count_dec(); | thread_count_dec(); | ||||
} | } | ||||
void | void | ||||
thread_cow_get_proc(struct thread *newtd, struct proc *p) | thread_cow_get_proc(struct thread *newtd, struct proc *p) | ||||
▲ Show 20 Lines • Show All 923 Lines • Show Last 20 Lines |