Skip to content

Commit 15ece0c

Browse files
committed
core: Wire up spawn to the new scheduler
It will check which scheduler it is running under and create the correct type of task as appropriate. Most options aren't supported but basic spawning works.
1 parent 6773b63 commit 15ece0c

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/libcore/rt/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,24 @@ fn test_context() {
160160
sched.run();
161161
}
162162
}
163+
164+
// For setting up tests of the new scheduler
165+
#[cfg(test)]
166+
pub fn run_in_newsched_task(f: ~fn()) {
167+
use cell::Cell;
168+
use unstable::run_in_bare_thread;
169+
use self::sched::{Scheduler, Task};
170+
use self::uvio::UvEventLoop;
171+
172+
let f = Cell(Cell(f));
173+
174+
do run_in_bare_thread {
175+
let mut sched = ~UvEventLoop::new_scheduler();
176+
let f = f.take();
177+
let task = ~do Task::new(&mut sched.stack_pool) {
178+
(f.take())();
179+
};
180+
sched.task_queue.push_back(task);
181+
sched.run();
182+
}
183+
}

src/libcore/task/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,3 +1226,12 @@ fn test_spawn_thread_on_demand() {
12261226

12271227
port.recv();
12281228
}
1229+
1230+
#[test]
1231+
fn test_simple_newsched_spawn() {
1232+
use rt::run_in_newsched_task;
1233+
1234+
do run_in_newsched_task {
1235+
spawn(||())
1236+
}
1237+
}

src/libcore/task/spawn.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,35 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
531531
}
532532

533533
pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
534+
use rt::*;
535+
536+
match context() {
537+
OldTaskContext => {
538+
spawn_raw_oldsched(opts, f)
539+
}
540+
TaskContext => {
541+
spawn_raw_newsched(opts, f)
542+
}
543+
SchedulerContext => {
544+
fail!(~"can't spawn from scheduler context")
545+
}
546+
GlobalContext => {
547+
fail!(~"can't spawn from global context")
548+
}
549+
}
550+
}
551+
552+
fn spawn_raw_newsched(opts: TaskOpts, f: ~fn()) {
553+
use rt::sched::*;
554+
555+
// XXX: How to schedule a new task is a policy decision that shouldn't be made here
556+
let mut sched = Scheduler::take_local();
557+
let task = ~Task::new(&mut sched.stack_pool, f);
558+
sched.resume_task_from_running_task_direct(task);
559+
}
560+
561+
fn spawn_raw_oldsched(opts: TaskOpts, f: ~fn()) {
562+
534563
let (child_tg, ancestors, is_main) =
535564
gen_child_taskgroup(opts.linked, opts.supervised);
536565

0 commit comments

Comments
 (0)