Skip to content

Commit 473b4d1

Browse files
committed
core::rt: Rename Scheduler::local to Scheduler::unsafe_local
1 parent 3b8a354 commit 473b4d1

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/libcore/rt/sched/mod.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ pub impl Scheduler {
9595
// Give ownership of the scheduler (self) to the thread
9696
local::put(self);
9797

98-
do Scheduler::local |scheduler| {
98+
do Scheduler::unsafe_local |scheduler| {
9999
fn run_scheduler_once() {
100-
do Scheduler::local |scheduler| {
100+
do Scheduler::unsafe_local |scheduler| {
101101
if scheduler.resume_task_from_queue() {
102102
// Ok, a task ran. Nice! We'll do it again later
103103
scheduler.event_loop.callback(run_scheduler_once);
@@ -112,7 +112,11 @@ pub impl Scheduler {
112112
return local::take();
113113
}
114114

115-
fn local(f: &fn(&mut Scheduler)) {
115+
/// Get a mutable pointer to the thread-local scheduler.
116+
/// # Safety Note
117+
/// This allows other mutable aliases to the scheduler, both in the current
118+
/// execution context and other execution contexts.
119+
fn unsafe_local(f: &fn(&mut Scheduler)) {
116120
unsafe { local::borrow(f) }
117121
}
118122

@@ -204,7 +208,7 @@ pub impl Scheduler {
204208
}
205209

206210
// We could be executing in a different thread now
207-
do Scheduler::local |sched| {
211+
do Scheduler::unsafe_local |sched| {
208212
sched.run_cleanup_job();
209213
}
210214
}
@@ -228,7 +232,7 @@ pub impl Scheduler {
228232
}
229233

230234
// We could be executing in a different thread now
231-
do Scheduler::local |sched| {
235+
do Scheduler::unsafe_local |sched| {
232236
sched.run_cleanup_job();
233237
}
234238
}
@@ -327,13 +331,13 @@ pub impl Task {
327331
// This is the first code to execute after the initial
328332
// context switch to the task. The previous context may
329333
// have asked us to do some cleanup.
330-
do Scheduler::local |sched| {
334+
do Scheduler::unsafe_local |sched| {
331335
sched.run_cleanup_job();
332336
}
333337

334338
start();
335339

336-
do Scheduler::local |sched| {
340+
do Scheduler::unsafe_local |sched| {
337341
sched.terminate_current_task();
338342
}
339343
};
@@ -394,7 +398,7 @@ fn test_swap_tasks() {
394398
let mut sched = ~UvEventLoop::new_scheduler();
395399
let task1 = ~do Task::new(&mut sched.stack_pool) {
396400
unsafe { *count_ptr = *count_ptr + 1; }
397-
do Scheduler::local |sched| {
401+
do Scheduler::unsafe_local |sched| {
398402
let task2 = ~do Task::new(&mut sched.stack_pool) {
399403
unsafe { *count_ptr = *count_ptr + 1; }
400404
};
@@ -427,7 +431,7 @@ fn test_run_a_lot_of_tasks_queued() {
427431
assert!(count == MAX);
428432

429433
fn run_task(count_ptr: *mut int) {
430-
do Scheduler::local |sched| {
434+
do Scheduler::unsafe_local |sched| {
431435
let task = ~do Task::new(&mut sched.stack_pool) {
432436
unsafe {
433437
*count_ptr = *count_ptr + 1;
@@ -460,7 +464,7 @@ fn test_run_a_lot_of_tasks_direct() {
460464
assert!(count == MAX);
461465

462466
fn run_task(count_ptr: *mut int) {
463-
do Scheduler::local |sched| {
467+
do Scheduler::unsafe_local |sched| {
464468
let task = ~do Task::new(&mut sched.stack_pool) {
465469
unsafe {
466470
*count_ptr = *count_ptr + 1;
@@ -481,7 +485,7 @@ fn test_block_task() {
481485
do run_in_bare_thread {
482486
let mut sched = ~UvEventLoop::new_scheduler();
483487
let task = ~do Task::new(&mut sched.stack_pool) {
484-
do Scheduler::local |sched| {
488+
do Scheduler::unsafe_local |sched| {
485489
assert!(sched.in_task_context());
486490
do sched.deschedule_running_task_and_then() |sched, task| {
487491
assert!(!sched.in_task_context());

src/libcore/rt/uvio.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl IoFactory for UvIoFactory {
104104
let result_cell = empty_cell();
105105
let result_cell_ptr: *Cell<Option<~StreamObject>> = &result_cell;
106106

107-
do Scheduler::local |scheduler| {
107+
do Scheduler::unsafe_local |scheduler| {
108108
assert!(scheduler.in_task_context());
109109

110110
// Block this task and take ownership, switch to scheduler context
@@ -131,7 +131,7 @@ impl IoFactory for UvIoFactory {
131131
unsafe { (*result_cell_ptr).put_back(maybe_stream); }
132132

133133
// Context switch
134-
do Scheduler::local |scheduler| {
134+
do Scheduler::unsafe_local |scheduler| {
135135
scheduler.resume_task_immediately(task_cell.take());
136136
}
137137
}
@@ -178,7 +178,7 @@ impl TcpListener for UvTcpListener {
178178

179179
let server_tcp_watcher = self.watcher();
180180

181-
do Scheduler::local |scheduler| {
181+
do Scheduler::unsafe_local |scheduler| {
182182
assert!(scheduler.in_task_context());
183183

184184
do scheduler.deschedule_running_task_and_then |_, task| {
@@ -201,7 +201,7 @@ impl TcpListener for UvTcpListener {
201201

202202
rtdebug!("resuming task from listen");
203203
// Context switch
204-
do Scheduler::local |scheduler| {
204+
do Scheduler::unsafe_local |scheduler| {
205205
scheduler.resume_task_immediately(task_cell.take());
206206
}
207207
}
@@ -243,7 +243,7 @@ impl Stream for UvStream {
243243
let result_cell = empty_cell();
244244
let result_cell_ptr: *Cell<Result<uint, ()>> = &result_cell;
245245

246-
do Scheduler::local |scheduler| {
246+
do Scheduler::unsafe_local |scheduler| {
247247
assert!(scheduler.in_task_context());
248248
let watcher = self.watcher();
249249
let buf_ptr: *&mut [u8] = &buf;
@@ -275,7 +275,7 @@ impl Stream for UvStream {
275275

276276
unsafe { (*result_cell_ptr).put_back(result); }
277277

278-
do Scheduler::local |scheduler| {
278+
do Scheduler::unsafe_local |scheduler| {
279279
scheduler.resume_task_immediately(task_cell.take());
280280
}
281281
}
@@ -289,7 +289,7 @@ impl Stream for UvStream {
289289
fn write(&mut self, buf: &[u8]) -> Result<(), ()> {
290290
let result_cell = empty_cell();
291291
let result_cell_ptr: *Cell<Result<(), ()>> = &result_cell;
292-
do Scheduler::local |scheduler| {
292+
do Scheduler::unsafe_local |scheduler| {
293293
assert!(scheduler.in_task_context());
294294
let watcher = self.watcher();
295295
let buf_ptr: *&[u8] = &buf;
@@ -308,7 +308,7 @@ impl Stream for UvStream {
308308

309309
unsafe { (*result_cell_ptr).put_back(result); }
310310

311-
do Scheduler::local |scheduler| {
311+
do Scheduler::unsafe_local |scheduler| {
312312
scheduler.resume_task_immediately(task_cell.take());
313313
}
314314
}
@@ -326,7 +326,7 @@ fn test_simple_io_no_connect() {
326326
do run_in_bare_thread {
327327
let mut sched = ~UvEventLoop::new_scheduler();
328328
let task = ~do Task::new(&mut sched.stack_pool) {
329-
do Scheduler::local |sched| {
329+
do Scheduler::unsafe_local |sched| {
330330
let io = sched.event_loop.io().unwrap();
331331
let addr = Ipv4(127, 0, 0, 1, 2926);
332332
let maybe_chan = io.connect(addr);
@@ -346,7 +346,7 @@ fn test_simple_tcp_server_and_client() {
346346
let addr = Ipv4(127, 0, 0, 1, 2929);
347347

348348
let client_task = ~do Task::new(&mut sched.stack_pool) {
349-
do Scheduler::local |sched| {
349+
do Scheduler::unsafe_local |sched| {
350350
let io = sched.event_loop.io().unwrap();
351351
let mut stream = io.connect(addr).unwrap();
352352
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
@@ -355,7 +355,7 @@ fn test_simple_tcp_server_and_client() {
355355
};
356356

357357
let server_task = ~do Task::new(&mut sched.stack_pool) {
358-
do Scheduler::local |sched| {
358+
do Scheduler::unsafe_local |sched| {
359359
let io = sched.event_loop.io().unwrap();
360360
let mut listener = io.bind(addr).unwrap();
361361
let mut stream = listener.listen().unwrap();
@@ -385,7 +385,7 @@ fn test_read_and_block() {
385385
let addr = Ipv4(127, 0, 0, 1, 2930);
386386

387387
let client_task = ~do Task::new(&mut sched.stack_pool) {
388-
do Scheduler::local |sched| {
388+
do Scheduler::unsafe_local |sched| {
389389
let io = sched.event_loop.io().unwrap();
390390
let mut stream = io.connect(addr).unwrap();
391391
stream.write([0, 1, 2, 3, 4, 5, 6, 7]);
@@ -397,7 +397,7 @@ fn test_read_and_block() {
397397
};
398398

399399
let server_task = ~do Task::new(&mut sched.stack_pool) {
400-
do Scheduler::local |sched| {
400+
do Scheduler::unsafe_local |sched| {
401401
let io = sched.event_loop.io().unwrap();
402402
let mut listener = io.bind(addr).unwrap();
403403
let mut stream = listener.listen().unwrap();
@@ -416,7 +416,7 @@ fn test_read_and_block() {
416416
}
417417
reads += 1;
418418

419-
do Scheduler::local |scheduler| {
419+
do Scheduler::unsafe_local |scheduler| {
420420
// Yield to the other task in hopes that it
421421
// will trigger a read callback while we are
422422
// not ready for it
@@ -448,7 +448,7 @@ fn test_read_read_read() {
448448
let addr = Ipv4(127, 0, 0, 1, 2931);
449449

450450
let client_task = ~do Task::new(&mut sched.stack_pool) {
451-
do Scheduler::local |sched| {
451+
do Scheduler::unsafe_local |sched| {
452452
let io = sched.event_loop.io().unwrap();
453453
let mut stream = io.connect(addr).unwrap();
454454
let mut buf = [0, .. 2048];

0 commit comments

Comments
 (0)