]> git.lizzy.rs Git - rust.git/commitdiff
Move RacyCell to `std::comm`
authorFlavio Percoco <flaper87@gmail.com>
Mon, 22 Dec 2014 11:29:46 +0000 (12:29 +0100)
committerFlavio Percoco <flaper87@gmail.com>
Fri, 26 Dec 2014 16:26:33 +0000 (17:26 +0100)
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.

src/libcore/atomic.rs
src/libcore/cell.rs
src/libstd/comm/mod.rs
src/libstd/sync/mutex.rs
src/libstd/sys/unix/mutex.rs
src/libstd/thread.rs
src/libstd/thread_local/scoped.rs
src/test/run-pass/issue-17718-static-unsafe-interior.rs

index a34f13d127c07d468ef8fb9c69b738cb7ed66225..9452d0a64bf63e914333fa299728bc9656f5b739 100644 (file)
 
 pub use self::Ordering::*;
 
+use kinds::Sync;
+
 use intrinsics;
-use cell::{UnsafeCell, RacyCell};
+use cell::UnsafeCell;
 
 /// A boolean type which can be safely shared between threads.
 #[stable]
 pub struct AtomicBool {
-    v: RacyCell<uint>,
+    v: UnsafeCell<uint>,
 }
 
+unsafe impl Sync for AtomicBool {}
+
 /// A signed integer type which can be safely shared between threads.
 #[stable]
 pub struct AtomicInt {
-    v: RacyCell<int>,
+    v: UnsafeCell<int>,
 }
 
+unsafe impl Sync for AtomicInt {}
+
 /// An unsigned integer type which can be safely shared between threads.
 #[stable]
 pub struct AtomicUint {
-    v: RacyCell<uint>,
+    v: UnsafeCell<uint>,
 }
 
+unsafe impl Sync for AtomicUint {}
+
 /// A raw pointer type which can be safely shared between threads.
 #[stable]
 pub struct AtomicPtr<T> {
-    p: RacyCell<uint>,
+    p: UnsafeCell<uint>,
 }
 
+unsafe impl<T> Sync for AtomicPtr<T> {}
+
 /// Atomic memory orderings
 ///
 /// Memory orderings limit the ways that both the compiler and CPU may reorder
@@ -80,15 +90,15 @@ pub enum Ordering {
 /// An `AtomicBool` initialized to `false`.
 #[unstable = "may be renamed, pending conventions for static initalizers"]
 pub const INIT_ATOMIC_BOOL: AtomicBool =
-        AtomicBool { v: RacyCell(UnsafeCell { value: 0 }) };
+        AtomicBool { v: UnsafeCell { value: 0 } };
 /// An `AtomicInt` initialized to `0`.
 #[unstable = "may be renamed, pending conventions for static initalizers"]
 pub const INIT_ATOMIC_INT: AtomicInt =
-        AtomicInt { v: RacyCell(UnsafeCell { value: 0 }) };
+        AtomicInt { v: UnsafeCell { value: 0 } };
 /// An `AtomicUint` initialized to `0`.
 #[unstable = "may be renamed, pending conventions for static initalizers"]
 pub const INIT_ATOMIC_UINT: AtomicUint =
-        AtomicUint { v: RacyCell(UnsafeCell { value: 0 }) };
+        AtomicUint { v: UnsafeCell { value: 0, } };
 
 // NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
 const UINT_TRUE: uint = -1;
@@ -108,7 +118,7 @@ impl AtomicBool {
     #[stable]
     pub fn new(v: bool) -> AtomicBool {
         let val = if v { UINT_TRUE } else { 0 };
-        AtomicBool { v: RacyCell::new(val) }
+        AtomicBool { v: UnsafeCell::new(val) }
     }
 
     /// Loads a value from the bool.
@@ -348,7 +358,7 @@ impl AtomicInt {
     #[inline]
     #[stable]
     pub fn new(v: int) -> AtomicInt {
-        AtomicInt {v: RacyCell::new(v)}
+        AtomicInt {v: UnsafeCell::new(v)}
     }
 
     /// Loads a value from the int.
@@ -534,7 +544,7 @@ impl AtomicUint {
     #[inline]
     #[stable]
     pub fn new(v: uint) -> AtomicUint {
-        AtomicUint { v: RacyCell::new(v) }
+        AtomicUint { v: UnsafeCell::new(v) }
     }
 
     /// Loads a value from the uint.
@@ -721,7 +731,7 @@ impl<T> AtomicPtr<T> {
     #[inline]
     #[stable]
     pub fn new(p: *mut T) -> AtomicPtr<T> {
-        AtomicPtr { p: RacyCell::new(p as uint) }
+        AtomicPtr { p: UnsafeCell::new(p as uint) }
     }
 
     /// Loads a value from the pointer.
index 6fc6c2a569d05514728c283715e5a9bb550a43c8..b45424a5eed3f7d4209e62880fd653eed298cbe5 100644 (file)
 use clone::Clone;
 use cmp::PartialEq;
 use default::Default;
-use kinds::{marker, Copy, Send, Sync};
+use kinds::{marker, Copy};
 use ops::{Deref, DerefMut, Drop};
 use option::Option;
 use option::Option::{None, Some};
@@ -555,28 +555,3 @@ pub unsafe fn into_inner(self) -> T { self.value }
     #[deprecated = "renamed to into_inner()"]
     pub unsafe fn unwrap(self) -> T { self.into_inner() }
 }
-
-/// 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> Sync for RacyCell<T> { } // Oh dear
index 618a5eebf0f9306f4820ef6c979f2fbeef9b29d9..c317be85ebc395979016ff8d72ee63a25efec3f8 100644 (file)
 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 @@ fn drop(&mut self) {
     }
 }
 
+/// 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::*;
index d2dafac281a878b0f4fab8b8326c3825580bcb07..77c358c62597b5018c6e4ef54b9140ff3e931f49 100644 (file)
@@ -10,8 +10,9 @@
 
 use prelude::*;
 
-use cell::{UnsafeCell, RacyCell};
-use kinds::{marker, Sync};
+use comm::RacyCell;
+use cell::UnsafeCell;
+use kinds::marker;
 use sync::{poison, AsMutexGuard};
 use sys_common::mutex as sys;
 
index 986f50bc8de9e2fb2a6af0ef6a02a24eb4d70ad6..3b0114b3e90e8f2d50a8d2cee59549afbda67ae9 100644 (file)
@@ -8,8 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use comm::RacyCell;
+use cell::UnsafeCell;
 use kinds::Sync;
-use cell::{UnsafeCell, RacyCell};
 use sys::sync as ffi;
 use sys_common::mutex;
 
index 92aa5201ec30120749ec6ab24a7794ae93e41055..45d5c5e0aab25df04aa2673a2c93fe54db137784 100644 (file)
 use any::Any;
 use borrow::IntoCow;
 use boxed::Box;
-use cell::RacyCell;
+use comm::RacyCell;
 use clone::Clone;
 use kinds::{Send, Sync};
 use ops::{Drop, FnOnce};
index d7ea163cc805e84ebbdb4ad6b59f0d142096abbf..3ea051b16f247972ee83a0c625fddb06a9e0d633 100644 (file)
@@ -196,11 +196,10 @@ pub fn is_set(&'static self) -> bool {
 
 #[cfg(not(any(windows, target_os = "android", target_os = "ios")))]
 mod imp {
-    use std::cell::UnsafeCell;
+    use std::comm::RacyCell;
 
-    // SNAP c9f6d69 switch to `Cell`
     #[doc(hidden)]
-    pub struct KeyInner<T> { pub inner: UnsafeCell<*mut T> }
+    pub struct KeyInner<T> { pub inner: RacyCell<*mut T> }
 
     unsafe impl<T> ::kinds::Sync for KeyInner<T> { }
 
index 17dd6d69fd4003251c6bd85c2552f2937cae8a69..82bfdb0612a64322daf0515ac85ec8d58055609e 100644 (file)
@@ -9,7 +9,8 @@
 // except according to those terms.
 
 use std::kinds::marker;
-use std::cell::{UnsafeCell, RacyCell};
+use std::comm::RacyCell;
+use std::cell::UnsafeCell;
 
 struct MyUnsafe<T> {
     value: RacyCell<T>