Skip to content

Commit 441d8a6

Browse files
committed
---
yaml --- r: 55673 b: refs/heads/master c: 15ece0c h: refs/heads/master i: 55671: d32ff01 v: v3
1 parent e0a5a2e commit 441d8a6

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
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: 6773b63671081c722761d3980393642452c08157
2+
refs/heads/master: 15ece0c23ef9b2e696ea4e81bf088e37fedc5d01
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a

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

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

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