Skip to content

Commit a7a823c

Browse files
committed
---
yaml --- r: 65141 b: refs/heads/master c: 18fab45 h: refs/heads/master i: 65139: 4786c12 v: v3
1 parent 5e25a22 commit a7a823c

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 71aa6b6631547a7b2e6839931e73286e0bf6ce5d
2+
refs/heads/master: 18fab45aab8622b0bfbcd336d57652bfb2f4f4ac
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libcore/rt/local.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rt::sched::Scheduler;
12+
use rt::local_ptr;
13+
1114
pub trait Local {
1215
fn put_local(value: ~Self);
1316
fn take_local() -> ~Self;
14-
fn exists() -> bool;
15-
fn borrow(f: &fn(&mut Self));
16-
fn unsafe_borrow() -> *mut Self;
17+
fn exists_local() -> bool;
18+
fn borrow_local(f: &fn(&mut Self));
19+
unsafe fn unsafe_borrow_local() -> *mut Self;
1720
}
21+
22+
impl Local for Scheduler {
23+
fn put_local(value: ~Scheduler) { unsafe { local_ptr::put(value) }}
24+
fn take_local() -> ~Scheduler { unsafe { local_ptr::take() } }
25+
fn exists_local() -> bool { local_ptr::exists() }
26+
fn borrow_local(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } }
27+
unsafe fn unsafe_borrow_local() -> *mut Scheduler { local_ptr::unsafe_borrow() }
28+
}

trunk/src/libcore/rt/local_sched.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,30 @@ use rt::rtio::{EventLoop, IoFactoryObject};
2121
use unstable::finally::Finally;
2222
use rt::local_ptr;
2323
use tls = rt::thread_local_storage;
24+
use rt::local::Local;
2425

2526
#[cfg(test)] use rt::uv::uvio::UvEventLoop;
2627

2728
/// Give the Scheduler to thread-local storage
28-
pub fn put(sched: ~Scheduler) { unsafe { local_ptr::put(sched) } }
29+
pub fn put(sched: ~Scheduler) { Local::put_local(sched) }
2930

3031
/// Take ownership of the Scheduler from thread-local storage
31-
pub fn take() -> ~Scheduler { unsafe { local_ptr::take() } }
32+
pub fn take() -> ~Scheduler { Local::take_local() }
3233

3334
/// Check whether there is a thread-local Scheduler attached to the running thread
34-
pub fn exists() -> bool { local_ptr::exists() }
35+
pub fn exists() -> bool { Local::exists_local::<Scheduler>() }
3536

3637
/// Borrow the thread-local scheduler from thread-local storage.
3738
/// While the scheduler is borrowed it is not available in TLS.
38-
pub fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } }
39+
pub fn borrow(f: &fn(&mut Scheduler)) { Local::borrow_local(f) }
3940

4041
/// Borrow a mutable reference to the thread-local Scheduler
4142
///
4243
/// # Safety Note
4344
///
4445
/// Because this leaves the Scheduler in thread-local storage it is possible
4546
/// For the Scheduler pointer to be aliased
46-
pub unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() }
47+
pub unsafe fn unsafe_borrow() -> *mut Scheduler { Local::unsafe_borrow_local() }
4748

4849
pub unsafe fn unsafe_borrow_io() -> *mut IoFactoryObject {
4950
let sched = unsafe_borrow();

0 commit comments

Comments
 (0)