]> git.lizzy.rs Git - rust.git/blobdiff - src/libgreen/sched.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / libgreen / sched.rs
index f8272e5f2376e9b24b81561de1dc26b41c009017..b9144047df5c0b7e3017f3fdeb27bedd594a82d4 100644 (file)
@@ -180,7 +180,7 @@ pub fn new_special(pool_id: uint,
 
     // Take a main task to run, and a scheduler to run it in. Create a
     // scheduler task and bootstrap into it.
-    pub fn bootstrap(mut ~self) {
+    pub fn bootstrap(mut self: Box<Scheduler>) {
 
         // Build an Idle callback.
         let cb = box SchedRunner as Box<Callback + Send>;
@@ -219,12 +219,13 @@ pub fn bootstrap(mut ~self) {
         let message = stask.sched.get_mut_ref().message_queue.pop();
         rtassert!(match message { msgq::Empty => true, _ => false });
 
-        stask.task.get_mut_ref().destroyed = true;
+        stask.task.take().unwrap().drop();
     }
 
     // This does not return a scheduler, as the scheduler is placed
     // inside the task.
-    pub fn run(mut ~self, stask: Box<GreenTask>) -> Box<GreenTask> {
+    pub fn run(mut self: Box<Scheduler>, stask: Box<GreenTask>)
+               -> Box<GreenTask> {
 
         // This is unsafe because we need to place the scheduler, with
         // the event_loop inside, inside our task. But we still need a
@@ -271,7 +272,7 @@ pub fn run(mut ~self, stask: Box<GreenTask>) -> Box<GreenTask> {
     // If we try really hard to do some work, but no work is available to be
     // done, then we fall back to epoll() to block this thread waiting for more
     // work (instead of busy waiting).
-    fn run_sched_once(mut ~self, stask: Box<GreenTask>) {
+    fn run_sched_once(mut self: Box<Scheduler>, stask: Box<GreenTask>) {
         // Make sure that we're not lying in that the `stask` argument is indeed
         // the scheduler task for this scheduler.
         assert!(self.sched_task.is_none());
@@ -349,11 +350,10 @@ fn run_sched_once(mut ~self, stask: Box<GreenTask>) {
     // returns the still-available scheduler. At this point all
     // message-handling will count as a turn of work, and as a result
     // return None.
-    fn interpret_message_queue(mut ~self, stask: Box<GreenTask>,
+    fn interpret_message_queue(mut self: Box<Scheduler>,
+                               stask: Box<GreenTask>,
                                effort: EffortLevel)
-            -> (Box<Scheduler>, Box<GreenTask>, bool)
-    {
-
+                               -> (Box<Scheduler>, Box<GreenTask>, bool) {
         let msg = if effort == DontTryTooHard {
             self.message_queue.casual_pop()
         } else {
@@ -432,7 +432,7 @@ fn interpret_message_queue(mut ~self, stask: Box<GreenTask>,
         }
     }
 
-    fn do_work(mut ~self, stask: Box<GreenTask>)
+    fn do_work(mut self: Box<Scheduler>, stask: Box<GreenTask>)
                -> (Box<Scheduler>, Box<GreenTask>, bool) {
         rtdebug!("scheduler calling do work");
         match self.find_work() {
@@ -517,7 +517,7 @@ fn try_steals(&mut self) -> Option<Box<GreenTask>> {
     // * Task Routing Functions - Make sure tasks send up in the right
     // place.
 
-    fn process_task(mut ~self,
+    fn process_task(mut self: Box<Scheduler>,
                     cur: Box<GreenTask>,
                     mut next: Box<GreenTask>,
                     schedule_fn: SchedulingFn)
@@ -610,14 +610,14 @@ pub fn enqueue_task(&mut self, task: Box<GreenTask>) {
     // cleanup function f, which takes the scheduler and the
     // old task as inputs.
 
-    pub fn change_task_context(mut ~self,
-                               current_task: Box<GreenTask>,
+    pub fn change_task_context(mut self: Box<Scheduler>,
+                               mut current_task: Box<GreenTask>,
                                mut next_task: Box<GreenTask>,
                                f: |&mut Scheduler, Box<GreenTask>|)
                                -> Box<GreenTask> {
         let f_opaque = ClosureConverter::from_fn(f);
 
-        let current_task_dupe = &*current_task as *GreenTask;
+        let current_task_dupe = &mut *current_task as *mut GreenTask;
 
         // The current task is placed inside an enum with the cleanup
         // function. This enum is then placed inside the scheduler.
@@ -693,7 +693,7 @@ pub fn get_contexts<'a>(current_task: &mut GreenTask,
 
     // * Context Swapping Helpers - Here be ugliness!
 
-    pub fn resume_task_immediately(~self,
+    pub fn resume_task_immediately(self: Box<Scheduler>,
                                    cur: Box<GreenTask>,
                                    next: Box<GreenTask>)
                                    -> (Box<Scheduler>, Box<GreenTask>) {
@@ -733,7 +733,7 @@ fn resume_task_immediately_cl(sched: Box<Scheduler>,
     /// This situation is currently prevented, or in other words it is
     /// guaranteed that this function will not return before the given closure
     /// has returned.
-    pub fn deschedule_running_task_and_then(mut ~self,
+    pub fn deschedule_running_task_and_then(mut self: Box<Scheduler>,
                                             cur: Box<GreenTask>,
                                             f: |&mut Scheduler, BlockedTask|) {
         // Trickier - we need to get the scheduler task out of self
@@ -743,7 +743,7 @@ pub fn deschedule_running_task_and_then(mut ~self,
         self.switch_running_tasks_and_then(cur, stask, f)
     }
 
-    pub fn switch_running_tasks_and_then(~self,
+    pub fn switch_running_tasks_and_then(self: Box<Scheduler>,
                                          cur: Box<GreenTask>,
                                          next: Box<GreenTask>,
                                          f: |&mut Scheduler, BlockedTask|) {
@@ -795,7 +795,9 @@ fn switch_task(sched: Box<Scheduler>,
 
     /// Called by a running task to end execution, after which it will
     /// be recycled by the scheduler for reuse in a new task.
-    pub fn terminate_current_task(mut ~self, cur: Box<GreenTask>) -> ! {
+    pub fn terminate_current_task(mut self: Box<Scheduler>,
+                                  cur: Box<GreenTask>)
+                                  -> ! {
         // Similar to deschedule running task and then, but cannot go through
         // the task-blocking path. The task is already dying.
         let stask = self.sched_task.take_unwrap();
@@ -807,7 +809,9 @@ pub fn terminate_current_task(mut ~self, cur: Box<GreenTask>) -> ! {
         fail!("should never return!");
     }
 
-    pub fn run_task(~self, cur: Box<GreenTask>, next: Box<GreenTask>) {
+    pub fn run_task(self: Box<Scheduler>,
+                    cur: Box<GreenTask>,
+                    next: Box<GreenTask>) {
         let (sched, task) =
             self.process_task(cur, next, Scheduler::switch_task);
         task.put_with_sched(sched);
@@ -823,7 +827,7 @@ pub fn run_task_later(mut cur: Box<GreenTask>, next: Box<GreenTask>) {
     /// to introduce some amount of randomness to the scheduler. Currently the
     /// randomness is a result of performing a round of work stealing (which
     /// may end up stealing from the current scheduler).
-    pub fn yield_now(mut ~self, cur: Box<GreenTask>) {
+    pub fn yield_now(mut self: Box<Scheduler>, cur: Box<GreenTask>) {
         // Async handles trigger the scheduler by calling yield_now on the local
         // task, which eventually gets us to here. See comments in SchedRunner
         // for more info on this.
@@ -842,7 +846,7 @@ pub fn yield_now(mut ~self, cur: Box<GreenTask>) {
         }
     }
 
-    pub fn maybe_yield(mut ~self, cur: Box<GreenTask>) {
+    pub fn maybe_yield(mut self: Box<Scheduler>, cur: Box<GreenTask>) {
         // It's possible for sched tasks to possibly call this function, and it
         // just means that they're likely sending on channels (which
         // occasionally call this function). Sched tasks follow different paths
@@ -871,7 +875,7 @@ pub fn maybe_yield(mut ~self, cur: Box<GreenTask>) {
 
     // * Utility Functions
 
-    pub fn sched_id(&self) -> uint { self as *Scheduler as uint }
+    pub fn sched_id(&self) -> uint { self as *const Scheduler as uint }
 
     pub fn run_cleanup_job(&mut self) {
         let cleanup_job = self.cleanup_job.take_unwrap();
@@ -959,13 +963,13 @@ pub fn run(self, sched: &mut Scheduler) {
 type UnsafeTaskReceiver = raw::Closure;
 trait ClosureConverter {
     fn from_fn(|&mut Scheduler, Box<GreenTask>|) -> Self;
-    fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>|;
+    fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>|:'static ;
 }
 impl ClosureConverter for UnsafeTaskReceiver {
     fn from_fn(f: |&mut Scheduler, Box<GreenTask>|) -> UnsafeTaskReceiver {
         unsafe { mem::transmute(f) }
     }
-    fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>| {
+    fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>|:'static {
         unsafe { mem::transmute(self) }
     }
 }
@@ -1413,7 +1417,7 @@ struct S { field: () }
 
             impl Drop for S {
                 fn drop(&mut self) {
-                    let _foo = box 0;
+                    let _foo = box 0i;
                 }
             }