Skip to content

Commit b530ca1

Browse files
committed
std: Make unlinking and task notification work with newsched
1 parent 5e7c5d6 commit b530ca1

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/libstd/rt/task.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,29 @@ mod test {
290290
a.next = Some(b);
291291
}
292292
}
293+
294+
// XXX: This is a copy of test_future_result in std::task.
295+
// It can be removed once the scheduler is turned on by default.
296+
#[test]
297+
fn future_result() {
298+
do run_in_newsched_task {
299+
use option::{Some, None};
300+
use task::*;
301+
302+
let mut result = None;
303+
let mut builder = task();
304+
builder.future_result(|r| result = Some(r));
305+
do builder.spawn {}
306+
assert_eq!(result.unwrap().recv(), Success);
307+
308+
result = None;
309+
let mut builder = task();
310+
builder.future_result(|r| result = Some(r));
311+
builder.unlinked();
312+
do builder.spawn {
313+
fail!();
314+
}
315+
assert_eq!(result.unwrap().recv(), Failure);
316+
}
317+
}
293318
}

src/libstd/task/spawn.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,29 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
578578
}
579579
}
580580

581-
fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) {
581+
fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
582582
use rt::sched::*;
583583

584-
let task = do Local::borrow::<Task, ~Task>() |running_task| {
585-
~running_task.new_child()
584+
let mut task = if opts.linked {
585+
do Local::borrow::<Task, ~Task>() |running_task| {
586+
~running_task.new_child()
587+
}
588+
} else {
589+
// An unlinked task is a new root in the task tree
590+
~Task::new_root()
586591
};
587592

593+
if opts.notify_chan.is_some() {
594+
let notify_chan = opts.notify_chan.swap_unwrap();
595+
let notify_chan = Cell::new(notify_chan);
596+
let on_exit: ~fn(bool) = |success| {
597+
notify_chan.take().send(
598+
if success { Success } else { Failure }
599+
)
600+
};
601+
task.on_exit = Some(on_exit);
602+
}
603+
588604
let mut sched = Local::take::<Scheduler>();
589605
let task = ~Coroutine::with_task(&mut sched.stack_pool,
590606
task, f);

0 commit comments

Comments
 (0)