about summary refs log tree commit diff
path: root/src/libcore/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-04-14 20:24:15 -0700
committerBrian Anderson <banderson@mozilla.com>2013-04-14 20:49:22 -0700
commita2e5827866876e9bafcf1f4e94f4e354e500420a (patch)
tree3f537c799d0aa8f3e20e8bff7de94c1f0c491a83 /src/libcore/rt
parent5f52aecb1e7a53bf46280d057654746c34e89859 (diff)
downloadrust-a2e5827866876e9bafcf1f4e94f4e354e500420a.tar.gz
rust-a2e5827866876e9bafcf1f4e94f4e354e500420a.zip
core::rt: All context switches are followed by a cleanup action
Diffstat (limited to 'src/libcore/rt')
-rw-r--r--src/libcore/rt/sched.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libcore/rt/sched.rs b/src/libcore/rt/sched.rs
index 11934d676e6..7cfb5b7903f 100644
--- a/src/libcore/rt/sched.rs
+++ b/src/libcore/rt/sched.rs
@@ -60,6 +60,7 @@ impl HackAroundBorrowCk for UnsafeTaskReceiver {
 }
 
 enum CleanupJob {
+    DoNothing,
     RescheduleTask(~Task),
     RecycleTask(~Task),
     GiveTask(~Task, UnsafeTaskReceiver)
@@ -148,6 +149,7 @@ pub impl Scheduler {
 
         // Store the task in the scheduler so it can be grabbed later
         self.current_task = Some(task);
+        self.enqueue_cleanup_job(DoNothing);
 
         // Take pointers to both the task and scheduler's saved registers.
         {
@@ -243,14 +245,13 @@ pub impl Scheduler {
     }
 
     fn run_cleanup_job(&mut self) {
-        rtdebug!("running cleanup jobs");
+        rtdebug!("running cleanup job");
 
-        if self.cleanup_job.is_none() {
-            return;
-        }
+        assert!(self.cleanup_job.is_some());
 
         let cleanup_job = self.cleanup_job.swap_unwrap();
         match cleanup_job {
+            DoNothing => { }
             RescheduleTask(task) => {
                 // NB: Pushing to the *front* of the queue
                 self.task_queue.push_front(task);
@@ -278,9 +279,10 @@ pub impl Scheduler {
             Some(GiveTask(~ref task, _)) => {
                 Some(task)
             }
-            None => {
+            Some(DoNothing) => {
                 None
             }
+            None => fail!(fmt!("all context switches should have a cleanup job"))
         };
         // XXX: Pattern matching mutable pointers above doesn't work
         // because borrowck thinks the three patterns are conflicting