diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-05-19 01:04:01 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-20 15:20:49 -0700 |
| commit | b0722c55f8205a43a0b8124ca179dada766c23ed (patch) | |
| tree | 5c2a4120822ff96b2f51b3b078cda03a9b2d85ee /src/libcore/rt | |
| parent | fa18a861fbd934c295990e59b20c7a0498b88f08 (diff) | |
| download | rust-b0722c55f8205a43a0b8124ca179dada766c23ed.tar.gz rust-b0722c55f8205a43a0b8124ca179dada766c23ed.zip | |
core:rt:: Rename LocalServices to Task
Diffstat (limited to 'src/libcore/rt')
| -rw-r--r-- | src/libcore/rt/mod.rs | 16 | ||||
| -rw-r--r-- | src/libcore/rt/sched.rs | 14 | ||||
| -rw-r--r-- | src/libcore/rt/task.rs (renamed from src/libcore/rt/local_services.rs) | 47 | ||||
| -rw-r--r-- | src/libcore/rt/test.rs | 38 |
4 files changed, 52 insertions, 63 deletions
diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs index 3d51345336f..208a6de46e8 100644 --- a/src/libcore/rt/mod.rs +++ b/src/libcore/rt/mod.rs @@ -31,14 +31,8 @@ access to the global heap. Unlike most of `rt` the global heap is truly a global resource and generally operates independently of the rest of the runtime. -All other runtime features are 'local', either thread-local or -task-local. Those critical to the functioning of the language are -defined in the module `local_services`. Local services are those which -are expected to be available to Rust code generally but rely on -thread- or task-local state. These currently include the local heap, +All other runtime features are task-local, including the local heap, the garbage collector, local storage, logging and the stack unwinder. -Local services are primarily implemented for tasks, but may also -be implemented for use outside of tasks. The relationship between `rt` and the rest of the core library is not entirely clear yet and some modules will be moving into or @@ -67,7 +61,10 @@ use ptr::Ptr; /// The global (exchange) heap. pub mod global_heap; -/// The Scheduler and Coroutine types. +/// Implementations of language-critical runtime features like @. +pub mod task; + +/// The coroutine task scheduler, built on the `io` event loop. mod sched; /// Thread-local access to the current Scheduler. @@ -77,9 +74,6 @@ pub mod local_sched; #[path = "io/mod.rs"] pub mod io; -/// Thread-local implementations of language-critical runtime features like @. -pub mod local_services; - /// The EventLoop and internal synchronous I/O interface. mod rtio; diff --git a/src/libcore/rt/sched.rs b/src/libcore/rt/sched.rs index 7099ae865e9..4b2165b4d2a 100644 --- a/src/libcore/rt/sched.rs +++ b/src/libcore/rt/sched.rs @@ -16,7 +16,7 @@ use super::work_queue::WorkQueue; use super::stack::{StackPool, StackSegment}; use super::rtio::{EventLoop, EventLoopObject}; use super::context::Context; -use super::local_services::LocalServices; +use super::task::Task; use cell::Cell; // A more convenient name for external callers, e.g. `local_sched::take()` @@ -350,16 +350,16 @@ pub struct Coroutine { /// the task is dead priv saved_context: Context, /// The heap, GC, unwinding, local storage, logging - local_services: LocalServices + task: Task } pub impl Coroutine { fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine { - Coroutine::with_local(stack_pool, LocalServices::new(), start) + Coroutine::with_task(stack_pool, Task::new(), start) } - fn with_local(stack_pool: &mut StackPool, - local_services: LocalServices, + fn with_task(stack_pool: &mut StackPool, + task: Task, start: ~fn()) -> Coroutine { let start = Coroutine::build_start_wrapper(start); let mut stack = stack_pool.take_segment(MIN_STACK_SIZE); @@ -368,7 +368,7 @@ pub impl Coroutine { return Coroutine { current_stack_segment: stack, saved_context: initial_context, - local_services: local_services + task: task }; } @@ -385,7 +385,7 @@ pub impl Coroutine { let sched = local_sched::unsafe_borrow(); let task = (*sched).current_task.get_mut_ref(); // FIXME #6141: shouldn't neet to put `start()` in another closure - task.local_services.run(||start()); + task.task.run(||start()); } let sched = local_sched::take(); diff --git a/src/libcore/rt/local_services.rs b/src/libcore/rt/task.rs index 8d6873be8cd..c3832d1338a 100644 --- a/src/libcore/rt/local_services.rs +++ b/src/libcore/rt/task.rs @@ -13,11 +13,6 @@ //! local storage, and logging. Even a 'freestanding' Rust would likely want //! to implement this. -//! Local services may exist in at least three different contexts: -//! when running as a task, when running in the scheduler's context, -//! or when running outside of a scheduler but with local services -//! (freestanding rust with local services?). - use prelude::*; use libc::{c_void, uintptr_t}; use cast::transmute; @@ -25,7 +20,7 @@ use super::sched::local_sched; use super::local_heap::LocalHeap; use rt::logging::StdErrLogger; -pub struct LocalServices { +pub struct Task { heap: LocalHeap, gc: GarbageCollector, storage: LocalStorage, @@ -41,9 +36,9 @@ pub struct Unwinder { unwinding: bool, } -impl LocalServices { - pub fn new() -> LocalServices { - LocalServices { +impl Task { + pub fn new() -> Task { + Task { heap: LocalHeap::new(), gc: GarbageCollector, storage: LocalStorage(ptr::null(), None), @@ -53,8 +48,8 @@ impl LocalServices { } } - pub fn without_unwinding() -> LocalServices { - LocalServices { + pub fn without_unwinding() -> Task { + Task { heap: LocalHeap::new(), gc: GarbageCollector, storage: LocalStorage(ptr::null(), None), @@ -66,9 +61,9 @@ impl LocalServices { pub fn run(&mut self, f: &fn()) { // This is just an assertion that `run` was called unsafely - // and this instance of LocalServices is still accessible. - do borrow_local_services |sched| { - assert!(ptr::ref_eq(sched, self)); + // and this instance of Task is still accessible. + do borrow_local_task |task| { + assert!(ptr::ref_eq(task, self)); } match self.unwinder { @@ -86,14 +81,14 @@ impl LocalServices { /// Must be called manually before finalization to clean up /// thread-local resources. Some of the routines here expect - /// LocalServices to be available recursively so this must be - /// called unsafely, without removing LocalServices from + /// Task to be available recursively so this must be + /// called unsafely, without removing Task from /// thread-local-storage. fn destroy(&mut self) { // This is just an assertion that `destroy` was called unsafely - // and this instance of LocalServices is still accessible. - do borrow_local_services |sched| { - assert!(ptr::ref_eq(sched, self)); + // and this instance of Task is still accessible. + do borrow_local_task |task| { + assert!(ptr::ref_eq(task, self)); } match self.storage { LocalStorage(ptr, Some(ref dtor)) => { @@ -105,7 +100,7 @@ impl LocalServices { } } -impl Drop for LocalServices { +impl Drop for Task { fn finalize(&self) { assert!(self.destroyed) } } @@ -156,11 +151,11 @@ impl Unwinder { /// Borrow a pointer to the installed local services. /// Fails (likely aborting the process) if local services are not available. -pub fn borrow_local_services(f: &fn(&mut LocalServices)) { +pub fn borrow_local_task(f: &fn(&mut Task)) { do local_sched::borrow |sched| { match sched.current_task { Some(~ref mut task) => { - f(&mut task.local_services) + f(&mut task.task) } None => { fail!("no local services for schedulers yet") @@ -169,10 +164,10 @@ pub fn borrow_local_services(f: &fn(&mut LocalServices)) { } } -pub unsafe fn unsafe_borrow_local_services() -> *mut LocalServices { +pub unsafe fn unsafe_borrow_local_task() -> *mut Task { match (*local_sched::unsafe_borrow()).current_task { Some(~ref mut task) => { - let s: *mut LocalServices = &mut task.local_services; + let s: *mut Task = &mut task.task; return s; } None => { @@ -182,9 +177,9 @@ pub unsafe fn unsafe_borrow_local_services() -> *mut LocalServices { } } -pub unsafe fn unsafe_try_borrow_local_services() -> Option<*mut LocalServices> { +pub unsafe fn unsafe_try_borrow_local_task() -> Option<*mut Task> { if local_sched::exists() { - Some(unsafe_borrow_local_services()) + Some(unsafe_borrow_local_task()) } else { None } diff --git a/src/libcore/rt/test.rs b/src/libcore/rt/test.rs index d739d0110ba..c3e52594d6e 100644 --- a/src/libcore/rt/test.rs +++ b/src/libcore/rt/test.rs @@ -13,7 +13,7 @@ use option::*; use cell::Cell; use result::{Result, Ok, Err}; use super::io::net::ip::{IpAddr, Ipv4}; -use rt::local_services::LocalServices; +use rt::task::Task; use rt::thread::Thread; /// Creates a new scheduler in a new thread and runs a task in it, @@ -28,9 +28,9 @@ pub fn run_in_newsched_task(f: ~fn()) { do run_in_bare_thread { let mut sched = ~UvEventLoop::new_scheduler(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f.take()); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f.take()); sched.enqueue_task(task); sched.run(); } @@ -41,9 +41,9 @@ pub fn spawntask(f: ~fn()) { use super::sched::*; let mut sched = local_sched::take(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f); do sched.switch_running_tasks_and_then(task) |task| { let task = Cell(task); let sched = local_sched::take(); @@ -56,9 +56,9 @@ pub fn spawntask_immediately(f: ~fn()) { use super::sched::*; let mut sched = local_sched::take(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f); do sched.switch_running_tasks_and_then(task) |task| { let task = Cell(task); do local_sched::borrow |sched| { @@ -72,9 +72,9 @@ pub fn spawntask_later(f: ~fn()) { use super::sched::*; let mut sched = local_sched::take(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f); sched.enqueue_task(task); local_sched::put(sched); @@ -89,9 +89,9 @@ pub fn spawntask_random(f: ~fn()) { let run_now: bool = Rand::rand(&mut rng); let mut sched = local_sched::take(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f); if run_now { do sched.switch_running_tasks_and_then(task) |task| { @@ -155,9 +155,9 @@ pub fn spawntask_thread(f: ~fn()) -> Thread { let f = Cell(f); let thread = do Thread::start { let mut sched = ~UvEventLoop::new_scheduler(); - let task = ~Coroutine::with_local(&mut sched.stack_pool, - LocalServices::without_unwinding(), - f.take()); + let task = ~Coroutine::with_task(&mut sched.stack_pool, + Task::without_unwinding(), + f.take()); sched.enqueue_task(task); sched.run(); }; |
