Skip to content

Commit 72933ae

Browse files
committed
---
yaml --- r: 66226 b: refs/heads/master c: b530ca1 h: refs/heads/master v: v3
1 parent f899a53 commit 72933ae

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5e7c5d6c3d532e7b536b76044cd47b72b8eadaad
2+
refs/heads/master: b530ca103388c99e774868645758785d6ad6b9a9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/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
}

trunk/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)