diff options
| author | Eric Reed <ereed@mozilla.com> | 2013-06-25 11:45:44 -0700 |
|---|---|---|
| committer | Eric Reed <ereed@mozilla.com> | 2013-06-25 11:45:44 -0700 |
| commit | 4870dce3ebfd0e988a2e45360c724ebe912c3ad5 (patch) | |
| tree | c676e677bf36924cbf177b0723b4ffe0fc435d40 /src/libstd/task/spawn.rs | |
| parent | 794923c99511398bc90400e380dd11770ec8e614 (diff) | |
| parent | e65d0cbabebc73f2c9733a7ed158576c9702e71e (diff) | |
| download | rust-4870dce3ebfd0e988a2e45360c724ebe912c3ad5.tar.gz rust-4870dce3ebfd0e988a2e45360c724ebe912c3ad5.zip | |
Merge remote-tracking branch 'upstream/io' into io
Conflicts: src/rt/rustrt.def.in
Diffstat (limited to 'src/libstd/task/spawn.rs')
| -rw-r--r-- | src/libstd/task/spawn.rs | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 9df93d19d21..63eb768d1c9 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -79,7 +79,6 @@ use cast; use cell::Cell; use container::Map; use comm::{Chan, GenericChan}; -use ptr; use hashmap::HashSet; use task::local_data_priv::{local_get, local_set, OldHandle}; use task::rt::rust_task; @@ -99,10 +98,6 @@ use rt::task::Task; #[cfg(test)] use comm; #[cfg(test)] use task; -macro_rules! move_it ( - { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } ) -) - type TaskSet = HashSet<*rust_task>; fn new_taskset() -> TaskSet { @@ -162,14 +157,14 @@ struct AncestorNode { struct AncestorList(Option<Exclusive<AncestorNode>>); // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. -#[inline(always)] +#[inline] fn access_group<U>(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U { unsafe { x.with(blk) } } -#[inline(always)] +#[inline] fn access_ancestors<U>(x: &Exclusive<AncestorNode>, blk: &fn(x: &mut AncestorNode) -> U) -> U { unsafe { @@ -583,13 +578,29 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) { } } -fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) { +fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { use rt::sched::*; - let task = do Local::borrow::<Task, ~Task>() |running_task| { - ~running_task.new_child() + let mut task = if opts.linked { + do Local::borrow::<Task, ~Task>() |running_task| { + ~running_task.new_child() + } + } else { + // An unlinked task is a new root in the task tree + ~Task::new_root() }; + if opts.notify_chan.is_some() { + let notify_chan = opts.notify_chan.swap_unwrap(); + let notify_chan = Cell::new(notify_chan); + let on_exit: ~fn(bool) = |success| { + notify_chan.take().send( + if success { Success } else { Failure } + ) + }; + task.on_exit = Some(on_exit); + } + let mut sched = Local::take::<Scheduler>(); let task = ~Coroutine::with_task(&mut sched.stack_pool, task, f); @@ -644,23 +655,16 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { notify_chan: Option<Chan<TaskResult>>, f: ~fn()) -> ~fn() { - let child_data = Cell::new((child_arc, ancestors)); + let child_data = Cell::new((notify_chan, child_arc, ancestors)); let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) - let mut (child_arc, ancestors) = child_data.take(); + let mut (notify_chan, child_arc, ancestors) = child_data.take(); // Child task runs this code. // Even if the below code fails to kick the child off, we must // send Something on the notify channel. - //let mut notifier = None;//notify_chan.map(|c| AutoNotify(c)); - let notifier = match notify_chan { - Some(ref notify_chan_value) => { - let moved_ncv = move_it!(*notify_chan_value); - Some(AutoNotify(moved_ncv)) - } - _ => None - }; + let notifier = notify_chan.map_consume(|c| AutoNotify(c)); if enlist_many(child, &child_arc, &mut ancestors) { let group = @@mut TCB(child, |
