X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=runtime%2Fruntime.c;h=d4946cfc0b47dd8fb8e673915786a41e44eb4958;hp=8056660694888b4b596e66a0c0c01655e2ac01ce;hb=dbcd4739e02b8e774e28b752c412d7e2f242cd47;hpb=fb536c12185fd1e339b5fd479d9ef84554b436df diff --git a/runtime/runtime.c b/runtime/runtime.c index 8056660..d4946cf 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -5,11 +5,12 @@ #include #include "common.h" #include "runtime.h" -#include "runtime_local.h" +#include "rlocal.h" #include "mem.h" #include "tls.h" DECLARE_THREAD_LOCAL(tid_, int); +DECLARE_THREAD_LOCAL(rand_seed_, unsigned); typedef struct thread_info { int thread_id; @@ -18,6 +19,8 @@ typedef struct thread_info { } thread_info_t; void nbd_init (void) { + sranddev(); + INIT_THREAD_LOCAL(rand_seed_); INIT_THREAD_LOCAL(tid_); SET_THREAD_LOCAL(tid_, 0); mem_init(); @@ -28,6 +31,8 @@ void nbd_init (void) { static void *worker (void *arg) { thread_info_t *ti = (thread_info_t *)arg; SET_THREAD_LOCAL(tid_, ti->thread_id); + LOCALIZE_THREAD_LOCAL(tid_, int); + SET_THREAD_LOCAL(rand_seed_, tid_+1); lwt_thread_init(ti->thread_id); rcu_thread_init(ti->thread_id); void *ret = ti->start_routine(ti->arg); @@ -42,3 +47,10 @@ int nbd_thread_create (pthread_t *restrict thread, int thread_id, void *(*start_ ti->arg = arg; return pthread_create(thread, NULL, worker, ti); } + +int nbd_rand (void) { + LOCALIZE_THREAD_LOCAL(rand_seed_, unsigned); + unsigned r = rand_r(&rand_seed_); + SET_THREAD_LOCAL(rand_seed_, r); + return r; +}