Skip to content

Commit 6f2e190

Browse files
committed
---
yaml --- r: 139242 b: refs/heads/try2 c: 5af5766 h: refs/heads/master v: v3
1 parent 0c9fb77 commit 6f2e190

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 044703435ba7e1338456f7a83393eb2c6fecf238
8+
refs/heads/try2: 5af5766512b0e90a3a076a09b35286aca332e48e
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/rt/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,10 @@ mod context;
4646
mod thread;
4747
pub mod env;
4848

49-
pub fn initialize() {
50-
unsafe { rust_initialize_global_state(); }
51-
extern {
52-
fn rust_initialize_global_state();
53-
}
54-
}
55-
5649
pub fn start(main: *u8, _argc: int, _argv: *c_char, _crate_map: *u8) -> int {
5750
use self::sched::{Scheduler, Task};
5851
use self::uvio::UvEventLoop;
5952

60-
// XXX: Would rather do this lazily in Scheduler
61-
initialize();
62-
6353
let loop_ = ~UvEventLoop::new();
6454
let mut sched = ~Scheduler::new(loop_);
6555
let main_task = ~do Task::new(&mut sched.stack_pool) {

branches/try2/src/libcore/rt/sched.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ enum CleanupJob {
7171
pub impl Scheduler {
7272

7373
static fn new(event_loop: ~EventLoopObject) -> Scheduler {
74+
75+
// Lazily initialize the global state, currently the scheduler TLS key
76+
unsafe { rust_initialize_global_state(); }
77+
extern {
78+
fn rust_initialize_global_state();
79+
}
80+
7481
Scheduler {
7582
event_loop: event_loop,
7683
task_queue: WorkQueue::new(),

branches/try2/src/rt/rust_builtin.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,6 @@ rust_call_nullary_fn(nullary_fn f) {
889889
f();
890890
}
891891

892-
893892
#ifndef _WIN32
894893
pthread_key_t sched_key;
895894
#else
@@ -901,16 +900,26 @@ rust_get_sched_tls_key() {
901900
return &sched_key;
902901
}
903902

903+
// Initialize the global state required by the new scheduler
904904
extern "C" CDECL void
905905
rust_initialize_global_state() {
906906

907+
static lock_and_signal init_lock;
908+
static bool initialized = false;
909+
910+
scoped_lock with(init_lock);
911+
912+
if (!initialized) {
913+
907914
#ifndef _WIN32
908-
assert(!pthread_key_create(&sched_key, NULL));
915+
assert(!pthread_key_create(&sched_key, NULL));
909916
#else
910-
sched_key = TlsAlloc();
911-
assert(sched_key != TLS_OUT_OF_INDEXES);
917+
sched_key = TlsAlloc();
918+
assert(sched_key != TLS_OUT_OF_INDEXES);
912919
#endif
913920

921+
initialized = true;
922+
}
914923
}
915924

916925
//

0 commit comments

Comments
 (0)