std: Make unlinking and task notification work with newsched

This commit is contained in:
Brian Anderson
2013-06-23 14:01:59 -07:00
parent 5e7c5d6c3d
commit b530ca1033
2 changed files with 44 additions and 3 deletions

View File

@@ -290,4 +290,29 @@ mod test {
a.next = Some(b);
}
}
// XXX: This is a copy of test_future_result in std::task.
// It can be removed once the scheduler is turned on by default.
#[test]
fn future_result() {
do run_in_newsched_task {
use option::{Some, None};
use task::*;
let mut result = None;
let mut builder = task();
builder.future_result(|r| result = Some(r));
do builder.spawn {}
assert_eq!(result.unwrap().recv(), Success);
result = None;
let mut builder = task();
builder.future_result(|r| result = Some(r));
builder.unlinked();
do builder.spawn {
fail!();
}
assert_eq!(result.unwrap().recv(), Failure);
}
}
}

View File

@@ -578,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| {
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);