@@ -212,7 +212,7 @@ pub impl Scheduler {
212
212
Context :: swap ( last_task_context, sched_context) ;
213
213
}
214
214
215
- // XXX: Should probably run cleanup jobs
215
+ self . run_cleanup_jobs ( ) ;
216
216
}
217
217
218
218
/// Switch directly to another task, without going through the scheduler.
@@ -233,7 +233,7 @@ pub impl Scheduler {
233
233
Context :: swap ( last_task_context, next_task_context) ;
234
234
}
235
235
236
- // XXX: Should probably run cleanup jobs
236
+ self . run_cleanup_jobs ( ) ;
237
237
}
238
238
239
239
// * Other stuff
@@ -245,7 +245,6 @@ pub impl Scheduler {
245
245
}
246
246
247
247
fn run_cleanup_jobs ( & mut self ) {
248
- assert ! ( !self . in_task_context( ) ) ;
249
248
rtdebug ! ( "running cleanup jobs" ) ;
250
249
251
250
while !self . cleanup_jobs . is_empty ( ) {
@@ -325,8 +324,12 @@ pub impl Task {
325
324
priv fn build_start_wrapper ( start : ~fn ( ) ) -> ~fn ( ) {
326
325
// XXX: The old code didn't have this extra allocation
327
326
let wrapper: ~fn ( ) = || {
328
- // XXX: Should probably run scheduler cleanup jobs for situations
329
- // where a task context switches directly to a new task
327
+ // This is the first code to execute after the initial
328
+ // context switch to the task. The previous context may
329
+ // have asked us to do some cleanup.
330
+ let mut sched = ThreadLocalScheduler :: new ( ) ;
331
+ let sched = sched. get_scheduler ( ) ;
332
+ sched. run_cleanup_jobs ( ) ;
330
333
331
334
start ( ) ;
332
335
0 commit comments