diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-19 15:25:35 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-20 15:20:50 -0700 |
| commit | 18fab45aab8622b0bfbcd336d57652bfb2f4f4ac (patch) | |
| tree | 5d922fc603c182f45e70e01199f714e8eb655ba3 /src/libcore/rt | |
| parent | 71aa6b6631547a7b2e6839931e73286e0bf6ce5d (diff) | |
| download | rust-18fab45aab8622b0bfbcd336d57652bfb2f4f4ac.tar.gz rust-18fab45aab8622b0bfbcd336d57652bfb2f4f4ac.zip | |
core::rt: Make local_sched a wrapper around Local
Diffstat (limited to 'src/libcore/rt')
| -rw-r--r-- | src/libcore/rt/local.rs | 17 | ||||
| -rw-r--r-- | src/libcore/rt/local_sched.rs | 11 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/libcore/rt/local.rs b/src/libcore/rt/local.rs index ec54bcb99dd..09e6ecda6a0 100644 --- a/src/libcore/rt/local.rs +++ b/src/libcore/rt/local.rs @@ -8,10 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use rt::sched::Scheduler; +use rt::local_ptr; + pub trait Local { fn put_local(value: ~Self); fn take_local() -> ~Self; - fn exists() -> bool; - fn borrow(f: &fn(&mut Self)); - fn unsafe_borrow() -> *mut Self; + fn exists_local() -> bool; + fn borrow_local(f: &fn(&mut Self)); + unsafe fn unsafe_borrow_local() -> *mut Self; } + +impl Local for Scheduler { + fn put_local(value: ~Scheduler) { unsafe { local_ptr::put(value) }} + fn take_local() -> ~Scheduler { unsafe { local_ptr::take() } } + fn exists_local() -> bool { local_ptr::exists() } + fn borrow_local(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } } + unsafe fn unsafe_borrow_local() -> *mut Scheduler { local_ptr::unsafe_borrow() } +} \ No newline at end of file diff --git a/src/libcore/rt/local_sched.rs b/src/libcore/rt/local_sched.rs index e3c0b4c4e88..8923bb45f58 100644 --- a/src/libcore/rt/local_sched.rs +++ b/src/libcore/rt/local_sched.rs @@ -21,21 +21,22 @@ use rt::rtio::{EventLoop, IoFactoryObject}; use unstable::finally::Finally; use rt::local_ptr; use tls = rt::thread_local_storage; +use rt::local::Local; #[cfg(test)] use rt::uv::uvio::UvEventLoop; /// Give the Scheduler to thread-local storage -pub fn put(sched: ~Scheduler) { unsafe { local_ptr::put(sched) } } +pub fn put(sched: ~Scheduler) { Local::put_local(sched) } /// Take ownership of the Scheduler from thread-local storage -pub fn take() -> ~Scheduler { unsafe { local_ptr::take() } } +pub fn take() -> ~Scheduler { Local::take_local() } /// Check whether there is a thread-local Scheduler attached to the running thread -pub fn exists() -> bool { local_ptr::exists() } +pub fn exists() -> bool { Local::exists_local::<Scheduler>() } /// Borrow the thread-local scheduler from thread-local storage. /// While the scheduler is borrowed it is not available in TLS. -pub fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } } +pub fn borrow(f: &fn(&mut Scheduler)) { Local::borrow_local(f) } /// Borrow a mutable reference to the thread-local Scheduler /// @@ -43,7 +44,7 @@ pub fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } } /// /// Because this leaves the Scheduler in thread-local storage it is possible /// For the Scheduler pointer to be aliased -pub unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() } +pub unsafe fn unsafe_borrow() -> *mut Scheduler { Local::unsafe_borrow_local() } pub unsafe fn unsafe_borrow_io() -> *mut IoFactoryObject { let sched = unsafe_borrow(); |
