File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -160,3 +160,24 @@ fn test_context() {
160
160
sched. run ( ) ;
161
161
}
162
162
}
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
+ }
Original file line number Diff line number Diff line change @@ -1226,3 +1226,12 @@ fn test_spawn_thread_on_demand() {
1226
1226
1227
1227
port. recv ( ) ;
1228
1228
}
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
+ }
Original file line number Diff line number Diff line change @@ -531,6 +531,35 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
531
531
}
532
532
533
533
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
+
534
563
let (child_tg, ancestors, is_main) =
535
564
gen_child_taskgroup(opts.linked, opts.supervised);
536
565
You can’t perform that action at this time.
0 commit comments