From 15ece0c23ef9b2e696ea4e81bf088e37fedc5d01 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 18 Apr 2013 18:38:12 -0700 Subject: 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. --- src/libcore/rt/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libcore/rt') diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs index ba61b49d14a..2b9f147bf62 100644 --- a/src/libcore/rt/mod.rs +++ b/src/libcore/rt/mod.rs @@ -160,3 +160,24 @@ fn test_context() { sched.run(); } } + +// For setting up tests of the new scheduler +#[cfg(test)] +pub fn run_in_newsched_task(f: ~fn()) { + use cell::Cell; + use unstable::run_in_bare_thread; + use self::sched::{Scheduler, Task}; + use self::uvio::UvEventLoop; + + let f = Cell(Cell(f)); + + do run_in_bare_thread { + let mut sched = ~UvEventLoop::new_scheduler(); + let f = f.take(); + let task = ~do Task::new(&mut sched.stack_pool) { + (f.take())(); + }; + sched.task_queue.push_back(task); + sched.run(); + } +} -- cgit 1.4.1-3-g733a5