Skip to content

Commit 6b084ba

Browse files
committed
core::rt: Insert calls to run_cleanup_tasks after all context switches
1 parent 1cb78e7 commit 6b084ba

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/libcore/rt/sched.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub impl Scheduler {
212212
Context::swap(last_task_context, sched_context);
213213
}
214214

215-
// XXX: Should probably run cleanup jobs
215+
self.run_cleanup_jobs();
216216
}
217217

218218
/// Switch directly to another task, without going through the scheduler.
@@ -233,7 +233,7 @@ pub impl Scheduler {
233233
Context::swap(last_task_context, next_task_context);
234234
}
235235

236-
// XXX: Should probably run cleanup jobs
236+
self.run_cleanup_jobs();
237237
}
238238

239239
// * Other stuff
@@ -245,7 +245,6 @@ pub impl Scheduler {
245245
}
246246

247247
fn run_cleanup_jobs(&mut self) {
248-
assert!(!self.in_task_context());
249248
rtdebug!("running cleanup jobs");
250249

251250
while !self.cleanup_jobs.is_empty() {
@@ -325,8 +324,12 @@ pub impl Task {
325324
priv fn build_start_wrapper(start: ~fn()) -> ~fn() {
326325
// XXX: The old code didn't have this extra allocation
327326
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();
330333

331334
start();
332335

0 commit comments

Comments
 (0)