about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/liballoc/arc.rs2
-rw-r--r--src/libstd/comm/mod.rs13
-rw-r--r--src/libstd/sync/mutex.rs9
-rw-r--r--src/libstd/sys/unix/mutex.rs5
-rw-r--r--src/libstd/thread.rs19
-rw-r--r--src/libstd/thread_local/scoped.rs4
-rw-r--r--src/test/run-pass/issue-17718-static-unsafe-interior.rs21
7 files changed, 37 insertions, 36 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 4810e15d68b..3d10628b1cb 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -139,7 +139,7 @@ struct ArcInner<T> {
     data: T,
 }
 
-impl<T: Sync + Send> Arc<T> {
+impl<T> Arc<T> {
     /// Constructs a new `Arc<T>`.
     ///
     /// # Examples
diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs
index c317be85ebc..269d988d1ee 100644
--- a/src/libstd/comm/mod.rs
+++ b/src/libstd/comm/mod.rs
@@ -1027,23 +1027,18 @@ 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>);
+struct RacyCell<T>(pub UnsafeCell<T>);
 
 impl<T> RacyCell<T> {
-    /// DOX
-    pub fn new(value: T) -> RacyCell<T> {
+
+    fn new(value: T) -> RacyCell<T> {
         RacyCell(UnsafeCell { value: value })
     }
 
-    /// DOX
-    pub unsafe fn get(&self) -> *mut T {
+    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> { }
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index 77c358c6259..fbbbb3e77a4 100644
--- a/src/libstd/sync/mutex.rs
+++ b/src/libstd/sync/mutex.rs
@@ -10,7 +10,6 @@
 
 use prelude::*;
 
-use comm::RacyCell;
 use cell::UnsafeCell;
 use kinds::marker;
 use sync::{poison, AsMutexGuard};
@@ -71,7 +70,7 @@ pub struct Mutex<T> {
     // time, so to ensure that the native mutex is used correctly we box the
     // inner lock to give it a constant address.
     inner: Box<StaticMutex>,
-    data: RacyCell<T>,
+    data: UnsafeCell<T>,
 }
 
 unsafe impl<T:Send> Send for Mutex<T> { }
@@ -101,7 +100,7 @@ unsafe impl<T:Send> Sync for Mutex<T> { }
 /// ```
 pub struct StaticMutex {
     lock: sys::Mutex,
-    poison: RacyCell<poison::Flag>,
+    poison: UnsafeCell<poison::Flag>,
 }
 
 unsafe impl Sync for StaticMutex {}
@@ -132,7 +131,7 @@ pub struct StaticMutexGuard {
 /// other mutex constants.
 pub const MUTEX_INIT: StaticMutex = StaticMutex {
     lock: sys::MUTEX_INIT,
-    poison: RacyCell(UnsafeCell { value: poison::Flag { failed: false } }),
+    poison: UnsafeCell { value: poison::Flag { failed: false } },
 };
 
 impl<T: Send> Mutex<T> {
@@ -140,7 +139,7 @@ impl<T: Send> Mutex<T> {
     pub fn new(t: T) -> Mutex<T> {
         Mutex {
             inner: box MUTEX_INIT,
-            data: RacyCell::new(t),
+            data: UnsafeCell::new(t),
         }
     }
 
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index 3b0114b3e90..81f8659d6ae 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -8,13 +8,12 @@
 // 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 sys::sync as ffi;
 use sys_common::mutex;
 
-pub struct Mutex { inner: RacyCell<ffi::pthread_mutex_t> }
+pub struct Mutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
 
 #[inline]
 pub unsafe fn raw(m: &Mutex) -> *mut ffi::pthread_mutex_t {
@@ -22,7 +21,7 @@ pub unsafe fn raw(m: &Mutex) -> *mut ffi::pthread_mutex_t {
 }
 
 pub const MUTEX_INIT: Mutex = Mutex {
-    inner: RacyCell(UnsafeCell { value: ffi::PTHREAD_MUTEX_INITIALIZER }),
+    inner: UnsafeCell { value: ffi::PTHREAD_MUTEX_INITIALIZER },
 };
 
 unsafe impl Sync for Mutex {}
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index 45d5c5e0aab..56731bd7ec3 100644
--- a/src/libstd/thread.rs
+++ b/src/libstd/thread.rs
@@ -127,7 +127,7 @@
 use any::Any;
 use borrow::IntoCow;
 use boxed::Box;
-use comm::RacyCell;
+use cell::UnsafeCell;
 use clone::Clone;
 use kinds::{Send, Sync};
 use ops::{Drop, FnOnce};
@@ -211,8 +211,8 @@ impl Builder {
     }
 
     fn spawn_inner<T: Send>(self, f: Thunk<(), T>) -> JoinGuard<T> {
-        let my_packet = Arc::new(RacyCell::new(None));
-        let their_packet = my_packet.clone();
+        let my_packet = Packet(Arc::new(UnsafeCell::new(None)));
+        let their_packet = Packet(my_packet.0.clone());
 
         let Builder { name, stack_size, stdout, stderr } = self;
 
@@ -266,7 +266,7 @@ impl Builder {
                 }
             };
             unsafe {
-                *their_packet.get() = Some(match (output, try_result) {
+                *their_packet.0.get() = Some(match (output, try_result) {
                     (Some(data), Ok(_)) => Ok(data),
                     (None, Err(cause)) => Err(cause),
                     _ => unreachable!()
@@ -383,6 +383,11 @@ impl thread_info::NewThread for Thread {
 /// A thread that completes without panicking is considered to exit successfully.
 pub type Result<T> = ::result::Result<T, Box<Any + Send>>;
 
+struct Packet<T>(Arc<UnsafeCell<Option<Result<T>>>>);
+
+unsafe impl<T:'static+Send> Send for Packet<T> {}
+unsafe impl<T> Sync for Packet<T> {}
+
 #[must_use]
 /// An RAII-style guard that will block until thread termination when dropped.
 ///
@@ -391,9 +396,11 @@ pub struct JoinGuard<T> {
     native: imp::rust_thread,
     thread: Thread,
     joined: bool,
-    packet: Arc<RacyCell<Option<Result<T>>>>,
+    packet: Packet<T>,
 }
 
+unsafe impl<T: Send> Sync for JoinGuard<T> {}
+
 impl<T: Send> JoinGuard<T> {
     /// Extract a handle to the thread this guard will join on.
     pub fn thread(&self) -> &Thread {
@@ -410,7 +417,7 @@ impl<T: Send> JoinGuard<T> {
         unsafe { imp::join(self.native) };
         self.joined = true;
         unsafe {
-            (*self.packet.get()).take().unwrap()
+            (*self.packet.0.get()).take().unwrap()
         }
     }
 
diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs
index 3ea051b16f2..756c86c2115 100644
--- a/src/libstd/thread_local/scoped.rs
+++ b/src/libstd/thread_local/scoped.rs
@@ -196,10 +196,10 @@ impl<T> Key<T> {
 
 #[cfg(not(any(windows, target_os = "android", target_os = "ios")))]
 mod imp {
-    use std::comm::RacyCell;
+    use std::cell::UnsafeCell;
 
     #[doc(hidden)]
-    pub struct KeyInner<T> { pub inner: RacyCell<*mut T> }
+    pub struct KeyInner<T> { pub inner: UnsafeCell<*mut T> }
 
     unsafe impl<T> ::kinds::Sync for KeyInner<T> { }
 
diff --git a/src/test/run-pass/issue-17718-static-unsafe-interior.rs b/src/test/run-pass/issue-17718-static-unsafe-interior.rs
index 82bfdb0612a..a25632b3376 100644
--- a/src/test/run-pass/issue-17718-static-unsafe-interior.rs
+++ b/src/test/run-pass/issue-17718-static-unsafe-interior.rs
@@ -9,29 +9,32 @@
 // except according to those terms.
 
 use std::kinds::marker;
-use std::comm::RacyCell;
 use std::cell::UnsafeCell;
 
 struct MyUnsafe<T> {
-    value: RacyCell<T>
+    value: UnsafeCell<T>
 }
 
 impl<T> MyUnsafe<T> {
     fn forbidden(&self) {}
 }
 
+impl<T: Send> Sync for MyUnsafe<T> {}
+
 enum UnsafeEnum<T> {
     VariantSafe,
-    VariantUnsafe(RacyCell<T>)
+    VariantUnsafe(UnsafeCell<T>)
 }
 
+impl<T: Send> Sync for UnsafeEnum<T> {}
+
 static STATIC1: UnsafeEnum<int> = UnsafeEnum::VariantSafe;
 
-static STATIC2: RacyCell<int> = RacyCell(UnsafeCell { value: 1 });
-const CONST: RacyCell<int> = RacyCell(UnsafeCell { value: 1 });
+static STATIC2: UnsafeCell<int> = UnsafeCell { value: 1 };
+const CONST: UnsafeCell<int> = UnsafeCell { value: 1 };
 static STATIC3: MyUnsafe<int> = MyUnsafe{value: CONST};
 
-static STATIC4: &'static RacyCell<int> = &STATIC2;
+static STATIC4: &'static UnsafeCell<int> = &STATIC2;
 
 struct Wrap<T> {
     value: T
@@ -39,13 +42,11 @@ struct Wrap<T> {
 
 unsafe impl<T: Send> Sync for Wrap<T> {}
 
-static UNSAFE: RacyCell<int> = RacyCell(UnsafeCell{value: 1});
-static WRAPPED_UNSAFE: Wrap<&'static RacyCell<int>> = Wrap { value: &UNSAFE };
+static UNSAFE: UnsafeCell<int> = UnsafeCell{value: 1};
+static WRAPPED_UNSAFE: Wrap<&'static UnsafeCell<int>> = Wrap { value: &UNSAFE };
 
 fn main() {
     let a = &STATIC1;
 
     STATIC3.forbidden()
 }
-
-