about summary refs log tree commit diff
path: root/src/libstd/rt/task.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-03 13:11:35 -0800
committerbors <bors@rust-lang.org>2014-02-03 13:11:35 -0800
commitd42521aa92006a3378c535adec80ae2257bff083 (patch)
tree0790d82726f49abc6d37b8ac5c8ca0fbec7e0685 /src/libstd/rt/task.rs
parentcb40eba4b1ce12914612914b94bdccd251a9f554 (diff)
parentacacfb20fd34162cfba5a4e7b5f1447e0403fa50 (diff)
downloadrust-d42521aa92006a3378c535adec80ae2257bff083.tar.gz
rust-d42521aa92006a3378c535adec80ae2257bff083.zip
auto merge of #11866 : alexcrichton/rust/atomic-u64, r=brson
Let's try this again.

This is an implementation of mutexes which I believe is free from undefined behavior of OS mutexes (the pitfall of the previous implementation).

This implementation is not ideal. There's a yield-loop spot, and it's not particularly fair with respect to lockers who steal without going through the normal code paths. That being said, I believe that this is a correct implementation which is a stepping stone to move from.

I haven't done rigorous benchmarking of this mutex, but preliminary results show that it's about 25% slower in the uncontended case on linux (same runtime on OSX), and it's actually faster than a pthreads mutex on high contention (again, not rigorous benchmarking, I just saw these numbers come up).
Diffstat (limited to 'src/libstd/rt/task.rs')
-rw-r--r--src/libstd/rt/task.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index 515eb93001a..fbe82531f69 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -250,9 +250,9 @@ impl Task {
     /// Wakes up a previously blocked task, optionally specifiying whether the
     /// current task can accept a change in scheduling. This function can only
     /// be called on tasks that were previously blocked in `deschedule`.
-    pub fn reawaken(mut ~self, can_resched: bool) {
+    pub fn reawaken(mut ~self) {
         let ops = self.imp.take_unwrap();
-        ops.reawaken(self, can_resched);
+        ops.reawaken(self);
     }
 
     /// Yields control of this task to another task. This function will
@@ -283,6 +283,12 @@ impl Task {
     pub fn stack_bounds(&self) -> (uint, uint) {
         self.imp.get_ref().stack_bounds()
     }
+
+    /// Returns whether it is legal for this task to block the OS thread that it
+    /// is running on.
+    pub fn can_block(&self) -> bool {
+        self.imp.get_ref().can_block()
+    }
 }
 
 impl Drop for Task {