Skip to content

Commit eb3288a

Browse files
committed
---
yaml --- r: 72147 b: refs/heads/dist-snap c: 15ece0c h: refs/heads/master i: 72145: ad00066 72143: 093c074 v: v3
1 parent 315395e commit eb3288a

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
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: 6773b63671081c722761d3980393642452c08157
10+
refs/heads/dist-snap: 15ece0c23ef9b2e696ea4e81bf088e37fedc5d01
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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+
}

branches/dist-snap/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+
}

branches/dist-snap/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)