diff options
Diffstat (limited to 'kern/thread.c')
-rw-r--r-- | kern/thread.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/kern/thread.c b/kern/thread.c index e9cb0c27..ec722898 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -99,6 +99,7 @@ #include <kern/string.h> #include <kern/task.h> #include <kern/thread.h> +#include <machine/atomic.h> #include <machine/cpu.h> #include <machine/mb.h> #include <machine/pmap.h> @@ -272,6 +273,16 @@ static struct { #define thread_ts_highest_round (thread_ts_highest_round_struct.value) /* + * Number of TSD keys actually allocated. + */ +static unsigned int thread_nr_keys __read_mostly; + +/* + * Destructors installed for each key. + */ +static thread_dtor_fn_t thread_dtors[THREAD_KEYS_MAX] __read_mostly; + +/* * List of threads pending for destruction by the reaper. */ static struct mutex thread_reap_lock; @@ -1443,6 +1454,7 @@ thread_init(struct thread *thread, void *stack, const struct thread_attr *attr, thread->sched_class = thread_policy_table[attr->policy]; cpumap_copy(&thread->cpumap, cpumap); thread_init_sched(thread, attr->priority); + memset(thread->tsd, 0, sizeof(thread->tsd)); thread->task = task; thread->stack = stack; strlcpy(thread->name, attr->name, sizeof(thread->name)); @@ -1936,3 +1948,17 @@ thread_tick(void) spinlock_unlock(&runq->lock); } + +void +thread_key_create(unsigned int *keyp, thread_dtor_fn_t dtor) +{ + unsigned int key; + + key = atomic_fetchadd_uint(&thread_nr_keys, 1); + + if (key >= THREAD_KEYS_MAX) + panic("thread: maximum number of keys exceeded"); + + thread_dtors[key] = dtor; + *keyp = key; +} |