2 * Written by Josh Dybnis and released to the public domain, as explained at
3 * http://creativecommons.org/licenses/publicdomain
8 #include "runtime_local.h"
12 DECLARE_THREAD_LOCAL(tid_, int);
14 typedef struct thread_info {
16 void *(*start_routine)(void *);
20 void nbd_init (void) {
21 INIT_THREAD_LOCAL(tid_);
22 SET_THREAD_LOCAL(tid_, 0);
28 static void *worker (void *arg) {
29 thread_info_t *ti = (thread_info_t *)arg;
30 SET_THREAD_LOCAL(tid_, ti->thread_id);
31 lwt_thread_init(ti->thread_id);
32 rcu_thread_init(ti->thread_id);
33 void *ret = ti->start_routine(ti->arg);
38 int nbd_thread_create (pthread_t *restrict thread, int thread_id, void *(*start_routine)(void *), void *restrict arg) {
39 thread_info_t *ti = (thread_info_t *)nbd_malloc(sizeof(thread_info_t));
40 ti->thread_id = thread_id;
41 ti->start_routine = start_routine;
43 return pthread_create(thread, NULL, worker, ti);