diff options
| author | bors <bors@rust-lang.org> | 2013-12-10 19:16:19 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-12-10 19:16:19 -0800 |
| commit | b8b16ae0996074861693f0f76d5d937fafe6a37e (patch) | |
| tree | 03f3fadcb4558ec1ddda3d61669636c1fcad1264 /src/libstd/task | |
| parent | ac4dd9efee9248f4c3235460f3c93acc9932eb5a (diff) | |
| parent | fd7a513bef7fe3c6f5128cc53135facca37f23e5 (diff) | |
| download | rust-b8b16ae0996074861693f0f76d5d937fafe6a37e.tar.gz rust-b8b16ae0996074861693f0f76d5d937fafe6a37e.zip | |
auto merge of #10791 : pcwalton/rust/decelling, r=pcwalton
34 uses of `Cell` remain. r? @alexcrichton
Diffstat (limited to 'src/libstd/task')
| -rw-r--r-- | src/libstd/task/mod.rs | 35 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 16 |
2 files changed, 19 insertions, 32 deletions
diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index a587515bb16..24a24f24818 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -55,7 +55,6 @@ use prelude::*; -use cell::Cell; use comm::{stream, Chan, GenericChan, GenericPort, Port, Peekable}; use result::{Result, Ok, Err}; use rt::in_green_task_context; @@ -284,10 +283,8 @@ impl TaskBuilder { f } }; - let prev_gen_body = Cell::new(prev_gen_body); let next_gen_body = { let f: proc(proc()) -> proc() = proc(body) { - let prev_gen_body = prev_gen_body.take(); wrapper(prev_gen_body(body)) }; f @@ -432,12 +429,11 @@ pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U { use rt::task::Task; if in_green_task_context() { - Local::borrow(|task: &mut Task| { - match task.name { - Some(ref name) => blk(Some(name.as_slice())), - None => blk(None) - } - }) + let mut task = Local::borrow(None::<Task>); + match task.get().name { + Some(ref name) => blk(Some(name.as_slice())), + None => blk(None) + } } else { fail!("no task name exists in non-green task context") } @@ -459,7 +455,8 @@ pub fn failing() -> bool { use rt::task::Task; - Local::borrow(|local: &mut Task| local.unwinder.unwinding) + let mut local = Local::borrow(None::<Task>); + local.get().unwinder.unwinding } // The following 8 tests test the following 2^3 combinations: @@ -548,11 +545,9 @@ struct Wrapper { fn test_add_wrapper() { let (po, ch) = stream::<()>(); let mut b0 = task(); - let ch = Cell::new(ch); do b0.add_wrapper |body| { - let ch = Cell::new(ch.take()); + let ch = ch; let result: proc() = proc() { - let ch = ch.take(); body(); ch.send(()); }; @@ -606,9 +601,9 @@ fn test_try_fail() { #[cfg(test)] fn get_sched_id() -> int { - Local::borrow(|sched: &mut ::rt::sched::Scheduler| { - sched.sched_id() as int - }) + use rt::sched::Scheduler; + let mut sched = Local::borrow(None::<Scheduler>); + sched.get().sched_id() as int } #[test] @@ -642,12 +637,10 @@ fn test_spawn_sched_childs_on_default_sched() { // Assuming tests run on the default scheduler let default_id = get_sched_id(); - let ch = Cell::new(ch); do spawn_sched(SingleThreaded) { let parent_sched_id = get_sched_id(); - let ch = Cell::new(ch.take()); + let ch = ch; do spawn { - let ch = ch.take(); let child_sched_id = get_sched_id(); assert!(parent_sched_id != child_sched_id); assert_eq!(child_sched_id, default_id); @@ -671,10 +664,10 @@ fn test_spawn_sched_blocking() { let (fin_po, fin_ch) = stream(); let mut lock = Mutex::new(); - let lock2 = Cell::new(lock.clone()); + let lock2 = lock.clone(); do spawn_sched(SingleThreaded) { - let mut lock = lock2.take(); + let mut lock = lock2; lock.lock(); start_ch.send(()); diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 153b3e4ce25..4ab7b74d300 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -77,7 +77,6 @@ use prelude::*; -use cell::Cell; use comm::{GenericChan, oneshot}; use rt::local::Local; use rt::sched::{Scheduler, Shutdown, TaskFromFriend}; @@ -134,23 +133,19 @@ pub fn spawn_raw(mut opts: TaskOpts, f: proc()) { // Create a task that will later be used to join with the new scheduler // thread when it is ready to terminate let (thread_port, thread_chan) = oneshot(); - let thread_port_cell = Cell::new(thread_port); let join_task = do Task::build_child(None) { debug!("running join task"); - let thread_port = thread_port_cell.take(); let thread: Thread<()> = thread_port.recv(); thread.join(); }; // Put the scheduler into another thread - let new_sched_cell = Cell::new(new_sched); - let orig_sched_handle_cell = Cell::new((*sched).make_handle()); - let join_task_cell = Cell::new(join_task); + let orig_sched_handle = (*sched).make_handle(); + let new_sched = new_sched; let thread = do Thread::start { - let mut new_sched = new_sched_cell.take(); - let mut orig_sched_handle = orig_sched_handle_cell.take(); - let join_task = join_task_cell.take(); + let mut new_sched = new_sched; + let mut orig_sched_handle = orig_sched_handle; let bootstrap_task = ~do Task::new_root(&mut new_sched.stack_pool, None) || { debug!("boostrapping a 1:1 scheduler"); @@ -178,9 +173,8 @@ pub fn spawn_raw(mut opts: TaskOpts, f: proc()) { if opts.notify_chan.is_some() { let notify_chan = opts.notify_chan.take_unwrap(); - let notify_chan = Cell::new(notify_chan); let on_exit: proc(UnwindResult) = proc(task_result) { - notify_chan.take().send(task_result) + notify_chan.send(task_result) }; task.death.on_exit = Some(on_exit); } |
