diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-03-15 18:35:33 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-03-18 17:00:35 -0700 |
| commit | 5af5766512b0e90a3a076a09b35286aca332e48e (patch) | |
| tree | d4fbefe51efa5acb6b27f1060e672706758da3e2 /src/rt | |
| parent | 044703435ba7e1338456f7a83393eb2c6fecf238 (diff) | |
| download | rust-5af5766512b0e90a3a076a09b35286aca332e48e.tar.gz rust-5af5766512b0e90a3a076a09b35286aca332e48e.zip | |
core: Initialize global state lazily in the Scheduler ctor
I don't want any global one-time initalization functions because that will make embedding harder.
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 9349db17d56..f586e05772b 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -889,7 +889,6 @@ rust_call_nullary_fn(nullary_fn f) { f(); } - #ifndef _WIN32 pthread_key_t sched_key; #else @@ -901,16 +900,26 @@ rust_get_sched_tls_key() { return &sched_key; } +// Initialize the global state required by the new scheduler extern "C" CDECL void rust_initialize_global_state() { + static lock_and_signal init_lock; + static bool initialized = false; + + scoped_lock with(init_lock); + + if (!initialized) { + #ifndef _WIN32 - assert(!pthread_key_create(&sched_key, NULL)); + assert(!pthread_key_create(&sched_key, NULL)); #else - sched_key = TlsAlloc(); - assert(sched_key != TLS_OUT_OF_INDEXES); + sched_key = TlsAlloc(); + assert(sched_key != TLS_OUT_OF_INDEXES); #endif + initialized = true; + } } // |
