Skip to content

Commit 1df5bfe

Browse files
committed
---
yaml --- r: 50001 b: refs/heads/auto c: 5af5766 h: refs/heads/master i: 49999: 5e4fb34 v: v3
1 parent 0063070 commit 1df5bfe

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
@@ -14,5 +14,5 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 044703435ba7e1338456f7a83393eb2c6fecf238
17+
refs/heads/auto: 5af5766512b0e90a3a076a09b35286aca332e48e
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167

branches/auto/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/auto/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/auto/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)