Skip to content

Commit a2e5827

Browse files
committed
core::rt: All context switches are followed by a cleanup action
1 parent 5f52aec commit a2e5827

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/libcore/rt/sched.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl HackAroundBorrowCk for UnsafeTaskReceiver {
6060
}
6161

6262
enum CleanupJob {
63+
DoNothing,
6364
RescheduleTask(~Task),
6465
RecycleTask(~Task),
6566
GiveTask(~Task, UnsafeTaskReceiver)
@@ -148,6 +149,7 @@ pub impl Scheduler {
148149

149150
// Store the task in the scheduler so it can be grabbed later
150151
self.current_task = Some(task);
152+
self.enqueue_cleanup_job(DoNothing);
151153

152154
// Take pointers to both the task and scheduler's saved registers.
153155
{
@@ -243,14 +245,13 @@ pub impl Scheduler {
243245
}
244246

245247
fn run_cleanup_job(&mut self) {
246-
rtdebug!("running cleanup jobs");
248+
rtdebug!("running cleanup job");
247249

248-
if self.cleanup_job.is_none() {
249-
return;
250-
}
250+
assert!(self.cleanup_job.is_some());
251251

252252
let cleanup_job = self.cleanup_job.swap_unwrap();
253253
match cleanup_job {
254+
DoNothing => { }
254255
RescheduleTask(task) => {
255256
// NB: Pushing to the *front* of the queue
256257
self.task_queue.push_front(task);
@@ -278,9 +279,10 @@ pub impl Scheduler {
278279
Some(GiveTask(~ref task, _)) => {
279280
Some(task)
280281
}
281-
None => {
282+
Some(DoNothing) => {
282283
None
283284
}
285+
None => fail!(fmt!("all context switches should have a cleanup job"))
284286
};
285287
// XXX: Pattern matching mutable pointers above doesn't work
286288
// because borrowck thinks the three patterns are conflicting

0 commit comments

Comments
 (0)