From 18fab45aab8622b0bfbcd336d57652bfb2f4f4ac Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 19 May 2013 15:25:35 -0700 Subject: [PATCH] core::rt: Make local_sched a wrapper around Local --- src/libcore/rt/local.rs | 17 ++++++++++++++--- 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 ec54bcb99dd7..09e6ecda6a04 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 e3c0b4c4e884..8923bb45f58d 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::() } /// 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();