Skip to content

Commit 18fab45

Browse files
committed
core::rt: Make local_sched a wrapper around Local
1 parent 71aa6b6 commit 18fab45

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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+
}

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)