about summary refs log tree commit diff
path: root/src/libstd/comm
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2014-12-22 12:29:46 +0100
committerFlavio Percoco <flaper87@gmail.com>2014-12-26 17:26:33 +0100
commite2116c8fba6e73bc2bbf7cb6bb41911d4daed043 (patch)
tree5484f1e0a4b7dfad3f2a363e5db1a39c9b50ccc9 /src/libstd/comm
parentf436f9ca2963e33cc41802370bb9c551c833970e (diff)
downloadrust-e2116c8fba6e73bc2bbf7cb6bb41911d4daed043.tar.gz
rust-e2116c8fba6e73bc2bbf7cb6bb41911d4daed043.zip
Move RacyCell to `std::comm`
RacyCell is not exactly what we'd like as a final implementation for
this. Therefore, we're moving it under `std::comm` and also making it
private.
Diffstat (limited to 'src/libstd/comm')
-rw-r--r--src/libstd/comm/mod.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs
index 618a5eebf0f..c317be85ebc 100644
--- a/src/libstd/comm/mod.rs
+++ b/src/libstd/comm/mod.rs
@@ -319,9 +319,10 @@ pub use self::TrySendError::*;
 use self::Flavor::*;
 
 use alloc::arc::Arc;
+use core::kinds;
 use core::kinds::marker;
 use core::mem;
-use core::cell::{UnsafeCell, RacyCell};
+use core::cell::UnsafeCell;
 
 pub use self::select::{Select, Handle};
 use self::select::StartResult;
@@ -1024,6 +1025,32 @@ impl<T: Send> Drop for Receiver<T> {
     }
 }
 
+/// A version of `UnsafeCell` intended for use in concurrent data
+/// structures (for example, you might put it in an `Arc`).
+pub struct RacyCell<T>(pub UnsafeCell<T>);
+
+impl<T> RacyCell<T> {
+    /// DOX
+    pub fn new(value: T) -> RacyCell<T> {
+        RacyCell(UnsafeCell { value: value })
+    }
+
+    /// DOX
+    pub unsafe fn get(&self) -> *mut T {
+        self.0.get()
+    }
+
+    /// DOX
+    pub unsafe fn into_inner(self) -> T {
+        self.0.into_inner()
+    }
+}
+
+unsafe impl<T:Send> Send for RacyCell<T> { }
+
+unsafe impl<T> kinds::Sync for RacyCell<T> { } // Oh dear
+
+
 #[cfg(test)]
 mod test {
     use prelude::*;