diff options
Diffstat (limited to 'src/libcore/task/spawn.rs')
| -rw-r--r-- | src/libcore/task/spawn.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index c71f7d26d40..47e38602995 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -531,6 +531,35 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) } pub fn spawn_raw(opts: TaskOpts, f: ~fn()) { + use rt::*; + + match context() { + OldTaskContext => { + spawn_raw_oldsched(opts, f) + } + TaskContext => { + spawn_raw_newsched(opts, f) + } + SchedulerContext => { + fail!(~"can't spawn from scheduler context") + } + GlobalContext => { + fail!(~"can't spawn from global context") + } + } +} + +fn spawn_raw_newsched(opts: TaskOpts, f: ~fn()) { + use rt::sched::*; + + // XXX: How to schedule a new task is a policy decision that shouldn't be made here + let mut sched = Scheduler::take_local(); + let task = ~Task::new(&mut sched.stack_pool, f); + sched.resume_task_from_running_task_direct(task); +} + +fn spawn_raw_oldsched(opts: TaskOpts, f: ~fn()) { + let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); |
