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"
15 DECLARE_THREAD_LOCAL(tid_, int);
17 typedef struct thread_info {
19 void *(*start_routine)(void *);
23 void nbd_init (void) {
24 INIT_THREAD_LOCAL(tid_, NULL);
31 static void *worker (void *arg) {
32 thread_info_t *ti = (thread_info_t *)arg;
33 SET_THREAD_LOCAL(tid_, ti->thread_id);
34 lwt_thread_init(ti->thread_id);
35 rcu_thread_init(ti->thread_id);
36 void *ret = ti->start_routine(ti->arg);
41 int nbd_thread_create (pthread_t *restrict thread, int thread_id, void *(*start_routine)(void *), void *restrict arg) {
42 thread_info_t *ti = (thread_info_t *)malloc(sizeof(thread_info_t));
43 ti->thread_id = thread_id;
44 ti->start_routine = start_routine;
46 return pthread_create(thread, NULL, worker, ti);