about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2014-12-22 00:49:42 +0100
committerFlavio Percoco <flaper87@gmail.com>2014-12-26 17:26:33 +0100
commitf436f9ca2963e33cc41802370bb9c551c833970e (patch)
treec79b09c0cb3024b389027fd2a501a44a0a1f9bb9 /src/libstd
parent686ce664da31f87b8d1c7377313f160d8fdcebe9 (diff)
downloadrust-f436f9ca2963e33cc41802370bb9c551c833970e.tar.gz
rust-f436f9ca2963e33cc41802370bb9c551c833970e.zip
Make Send and Sync traits unsafe
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_str.rs4
-rw-r--r--src/libstd/comm/blocking.rs5
-rw-r--r--src/libstd/comm/mod.rs4
-rw-r--r--src/libstd/comm/mpsc_queue.rs4
-rw-r--r--src/libstd/comm/spsc_queue.rs4
-rw-r--r--src/libstd/comm/sync.rs9
-rw-r--r--src/libstd/rt/exclusive.rs4
-rw-r--r--src/libstd/sync/mutex.rs9
-rw-r--r--src/libstd/sync/once.rs4
-rw-r--r--src/libstd/sys/common/helper_thread.rs4
-rw-r--r--src/libstd/sys/common/mutex.rs4
-rw-r--r--src/libstd/sys/unix/c.rs4
-rw-r--r--src/libstd/sys/unix/mutex.rs4
-rw-r--r--src/libstd/sys/unix/pipe.rs6
-rw-r--r--src/libstd/sys/unix/tcp.rs6
-rw-r--r--src/libstd/thread.rs7
-rw-r--r--src/libstd/thread_local/mod.rs4
-rw-r--r--src/libstd/thread_local/scoped.rs4
18 files changed, 54 insertions, 36 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs
index 27b63be6cd0..846b542d81a 100644
--- a/src/libstd/c_str.rs
+++ b/src/libstd/c_str.rs
@@ -89,8 +89,8 @@ pub struct CString {
     owns_buffer_: bool,
 }
 
-impl Send for CString { }
-impl Sync for CString { }
+unsafe impl Send for CString { }
+unsafe impl Sync for CString { }
 
 impl Clone for CString {
     /// Clone this CString into a new, uniquely owned CString. For safety
diff --git a/src/libstd/comm/blocking.rs b/src/libstd/comm/blocking.rs
index a154224824c..412b7161305 100644
--- a/src/libstd/comm/blocking.rs
+++ b/src/libstd/comm/blocking.rs
@@ -13,16 +13,19 @@
 use thread::Thread;
 use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, Ordering};
 use sync::Arc;
+use kinds::{Sync, Send};
 use kinds::marker::{NoSend, NoSync};
 use mem;
 use clone::Clone;
 
-#[deriving(Send, Sync)]
 struct Inner {
     thread: Thread,
     woken: AtomicBool,
 }
 
+unsafe impl Send for Inner {}
+unsafe impl Sync for Inner {}
+
 #[deriving(Clone)]
 pub struct SignalToken {
     inner: Arc<Inner>,
diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs
index 18b50c621e9..618a5eebf0f 100644
--- a/src/libstd/comm/mod.rs
+++ b/src/libstd/comm/mod.rs
@@ -363,7 +363,7 @@ pub struct Receiver<T> {
 
 // The receiver port can be sent from place to place, so long as it
 // is not used to receive non-sendable things.
-impl<T:Send> Send for Receiver<T> { }
+unsafe impl<T:Send> Send for Receiver<T> { }
 
 /// An iterator over messages on a receiver, this iterator will block
 /// whenever `next` is called, waiting for a new message, and `None` will be
@@ -382,7 +382,7 @@ pub struct Sender<T> {
 
 // The send port can be sent from place to place, so long as it
 // is not used to send non-sendable things.
-impl<T:Send> Send for Sender<T> { }
+unsafe impl<T:Send> Send for Sender<T> { }
 
 /// The sending-half of Rust's synchronous channel type. This half can only be
 /// owned by one task, but it can be cloned to send to other tasks.
diff --git a/src/libstd/comm/mpsc_queue.rs b/src/libstd/comm/mpsc_queue.rs
index 6298896a18b..cddef236664 100644
--- a/src/libstd/comm/mpsc_queue.rs
+++ b/src/libstd/comm/mpsc_queue.rs
@@ -76,8 +76,8 @@ pub struct Queue<T> {
     tail: UnsafeCell<*mut Node<T>>,
 }
 
-impl<T:Send> Send for Queue<T> { }
-impl<T:Send> Sync for Queue<T> { }
+unsafe impl<T:Send> Send for Queue<T> { }
+unsafe impl<T:Send> Sync for Queue<T> { }
 
 impl<T> Node<T> {
     unsafe fn new(v: Option<T>) -> *mut Node<T> {
diff --git a/src/libstd/comm/spsc_queue.rs b/src/libstd/comm/spsc_queue.rs
index dbf1f255997..becb78063ae 100644
--- a/src/libstd/comm/spsc_queue.rs
+++ b/src/libstd/comm/spsc_queue.rs
@@ -73,9 +73,9 @@ pub struct Queue<T> {
     cache_subtractions: AtomicUint,
 }
 
-impl<T: Send> Send for Queue<T> { }
+unsafe impl<T: Send> Send for Queue<T> { }
 
-impl<T: Send> Sync for Queue<T> { }
+unsafe impl<T: Send> Sync for Queue<T> { }
 
 impl<T: Send> Node<T> {
     fn new() -> *mut Node<T> {
diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs
index f4f4c7472e2..88338849965 100644
--- a/src/libstd/comm/sync.rs
+++ b/src/libstd/comm/sync.rs
@@ -53,11 +53,10 @@ pub struct Packet<T> {
     lock: Mutex<State<T>>,
 }
 
-impl<T:Send> Send for Packet<T> { }
+unsafe impl<T:Send> Send for Packet<T> { }
 
-impl<T:Send> Sync for Packet<T> { }
+unsafe impl<T:Send> Sync for Packet<T> { }
 
-#[deriving(Send)]
 struct State<T> {
     disconnected: bool, // Is the channel disconnected yet?
     queue: Queue,       // queue of senders waiting to send data
@@ -74,6 +73,8 @@ struct State<T> {
     canceled: Option<&'static mut bool>,
 }
 
+unsafe impl<T: Send> Send for State<T> {}
+
 /// Possible flavors of threads who can be blocked on this channel.
 enum Blocker {
     BlockedSender(SignalToken),
@@ -93,7 +94,7 @@ struct Node {
     next: *mut Node,
 }
 
-impl Send for Node {}
+unsafe impl Send for Node {}
 
 /// A simple ring-buffer
 struct Buffer<T> {
diff --git a/src/libstd/rt/exclusive.rs b/src/libstd/rt/exclusive.rs
index a878066ad16..88bdb29caec 100644
--- a/src/libstd/rt/exclusive.rs
+++ b/src/libstd/rt/exclusive.rs
@@ -26,9 +26,9 @@ pub struct Exclusive<T> {
     data: UnsafeCell<T>,
 }
 
-impl<T:Send> Send for Exclusive<T> { }
+unsafe impl<T:Send> Send for Exclusive<T> { }
 
-impl<T:Send> Sync for Exclusive<T> { }
+unsafe impl<T:Send> Sync for Exclusive<T> { }
 
 /// An RAII guard returned via `lock`
 pub struct ExclusiveGuard<'a, T:'a> {
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index 2849813c510..d2dafac281a 100644
--- a/src/libstd/sync/mutex.rs
+++ b/src/libstd/sync/mutex.rs
@@ -11,7 +11,7 @@
 use prelude::*;
 
 use cell::{UnsafeCell, RacyCell};
-use kinds::marker;
+use kinds::{marker, Sync};
 use sync::{poison, AsMutexGuard};
 use sys_common::mutex as sys;
 
@@ -73,9 +73,9 @@ pub struct Mutex<T> {
     data: RacyCell<T>,
 }
 
-impl<T:Send> Send for Mutex<T> { }
+unsafe impl<T:Send> Send for Mutex<T> { }
 
-impl<T:Send> Sync for Mutex<T> { }
+unsafe impl<T:Send> Sync for Mutex<T> { }
 
 /// The static mutex type is provided to allow for static allocation of mutexes.
 ///
@@ -98,12 +98,13 @@ impl<T:Send> Sync for Mutex<T> { }
 /// }
 /// // lock is unlocked here.
 /// ```
-#[deriving(Sync)]
 pub struct StaticMutex {
     lock: sys::Mutex,
     poison: RacyCell<poison::Flag>,
 }
 
+unsafe impl Sync for StaticMutex {}
+
 /// An RAII implementation of a "scoped lock" of a mutex. When this structure is
 /// dropped (falls out of scope), the lock will be unlocked.
 ///
diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs
index 4b940b0420a..4d9fbb59908 100644
--- a/src/libstd/sync/once.rs
+++ b/src/libstd/sync/once.rs
@@ -14,6 +14,7 @@
 //! example use case would be for initializing an FFI library.
 
 use int;
+use kinds::Sync;
 use mem::drop;
 use ops::FnOnce;
 use sync::atomic;
@@ -35,13 +36,14 @@ use sync::{StaticMutex, MUTEX_INIT};
 ///     // run initialization here
 /// });
 /// ```
-#[deriving(Sync)]
 pub struct Once {
     mutex: StaticMutex,
     cnt: atomic::AtomicInt,
     lock_cnt: atomic::AtomicInt,
 }
 
+unsafe impl Sync for Once {}
+
 /// Initialization value for static `Once` values.
 pub const ONCE_INIT: Once = Once {
     mutex: MUTEX_INIT,
diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs
index 9df69d8e0d6..b0137bdad06 100644
--- a/src/libstd/sys/common/helper_thread.rs
+++ b/src/libstd/sys/common/helper_thread.rs
@@ -59,9 +59,9 @@ pub struct Helper<M> {
     pub shutdown: UnsafeCell<bool>,
 }
 
-impl<M:Send> Send for Helper<M> { }
+unsafe impl<M:Send> Send for Helper<M> { }
 
-impl<M:Send> Sync for Helper<M> { }
+unsafe impl<M:Send> Sync for Helper<M> { }
 
 impl<M: Send> Helper<M> {
     /// Lazily boots a helper thread, becoming a no-op if the helper has already
diff --git a/src/libstd/sys/common/mutex.rs b/src/libstd/sys/common/mutex.rs
index 5869c280517..567c26956ef 100644
--- a/src/libstd/sys/common/mutex.rs
+++ b/src/libstd/sys/common/mutex.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use kinds::Sync;
 use sys::mutex as imp;
 
 /// An OS-based mutual exclusion lock.
@@ -15,9 +16,10 @@ use sys::mutex as imp;
 /// This is the thinnest cross-platform wrapper around OS mutexes. All usage of
 /// this mutex is unsafe and it is recommended to instead use the safe wrapper
 /// at the top level of the crate instead of this type.
-#[deriving(Sync)]
 pub struct Mutex(imp::Mutex);
 
+unsafe impl Sync for Mutex {}
+
 /// Constant initializer for statically allocated mutexes.
 pub const MUTEX_INIT: Mutex = Mutex(imp::MUTEX_INIT);
 
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs
index a5796f8dd01..a4ebcbd25d0 100644
--- a/src/libstd/sys/unix/c.rs
+++ b/src/libstd/sys/unix/c.rs
@@ -162,8 +162,8 @@ mod signal {
         sa_restorer: *mut libc::c_void,
     }
 
-    impl ::kinds::Send for sigaction { }
-    impl ::kinds::Sync for sigaction { }
+    unsafe impl ::kinds::Send for sigaction { }
+    unsafe impl ::kinds::Sync for sigaction { }
 
     #[repr(C)]
     #[cfg(target_word_size = "32")]
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index 52ed0649694..986f50bc8de 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -8,11 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use kinds::Sync;
 use cell::{UnsafeCell, RacyCell};
 use sys::sync as ffi;
 use sys_common::mutex;
 
-#[deriving(Sync)]
 pub struct Mutex { inner: RacyCell<ffi::pthread_mutex_t> }
 
 #[inline]
@@ -24,6 +24,8 @@ pub const MUTEX_INIT: Mutex = Mutex {
     inner: RacyCell(UnsafeCell { value: ffi::PTHREAD_MUTEX_INITIALIZER }),
 };
 
+unsafe impl Sync for Mutex {}
+
 impl Mutex {
     #[inline]
     pub unsafe fn new() -> Mutex {
diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs
index 8d1010937bc..c4aec82894f 100644
--- a/src/libstd/sys/unix/pipe.rs
+++ b/src/libstd/sys/unix/pipe.rs
@@ -210,12 +210,13 @@ impl Clone for UnixStream {
 // Unix Listener
 ////////////////////////////////////////////////////////////////////////////////
 
-#[deriving(Sync)]
 pub struct UnixListener {
     inner: Inner,
     path: CString,
 }
 
+unsafe impl Sync for UnixListener {}
+
 impl UnixListener {
     pub fn bind(addr: &CString) -> IoResult<UnixListener> {
         bind(addr, libc::SOCK_STREAM).map(|fd| {
@@ -253,7 +254,6 @@ pub struct UnixAcceptor {
     deadline: u64,
 }
 
-#[deriving(Sync)]
 struct AcceptorInner {
     listener: UnixListener,
     reader: FileDesc,
@@ -261,6 +261,8 @@ struct AcceptorInner {
     closed: atomic::AtomicBool,
 }
 
+unsafe impl Sync for AcceptorInner {}
+
 impl UnixAcceptor {
     pub fn fd(&self) -> fd_t { self.inner.listener.fd() }
 
diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs
index 60ca76171b1..e2a78947e16 100644
--- a/src/libstd/sys/unix/tcp.rs
+++ b/src/libstd/sys/unix/tcp.rs
@@ -29,11 +29,12 @@ pub use sys_common::net::TcpStream;
 // TCP listeners
 ////////////////////////////////////////////////////////////////////////////////
 
-#[deriving(Sync)]
 pub struct TcpListener {
     pub inner: FileDesc,
 }
 
+unsafe impl Sync for TcpListener {}
+
 impl TcpListener {
     pub fn bind(addr: ip::SocketAddr) -> IoResult<TcpListener> {
         let fd = try!(net::socket(addr, libc::SOCK_STREAM));
@@ -90,7 +91,6 @@ pub struct TcpAcceptor {
     deadline: u64,
 }
 
-#[deriving(Sync)]
 struct AcceptorInner {
     listener: TcpListener,
     reader: FileDesc,
@@ -98,6 +98,8 @@ struct AcceptorInner {
     closed: atomic::AtomicBool,
 }
 
+unsafe impl Sync for AcceptorInner {}
+
 impl TcpAcceptor {
     pub fn fd(&self) -> sock_t { self.inner.listener.fd() }
 
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index e3b97afb31d..92aa5201ec3 100644
--- a/src/libstd/thread.rs
+++ b/src/libstd/thread.rs
@@ -283,19 +283,22 @@ impl Builder {
     }
 }
 
-#[deriving(Sync)]
 struct Inner {
     name: Option<String>,
     lock: Mutex<bool>,          // true when there is a buffered unpark
     cvar: Condvar,
 }
 
-#[deriving(Clone, Sync)]
+unsafe impl Sync for Inner {}
+
+#[deriving(Clone)]
 /// A handle to a thread.
 pub struct Thread {
     inner: Arc<Inner>,
 }
 
+unsafe impl Sync for Thread {}
+
 impl Thread {
     // Used only internally to construct a thread object without spawning
     fn new(name: Option<String>) -> Thread {
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs
index 55fb3151133..242dceb4256 100644
--- a/src/libstd/thread_local/mod.rs
+++ b/src/libstd/thread_local/mod.rs
@@ -280,7 +280,7 @@ mod imp {
         pub dtor_running: UnsafeCell<bool>, // should be Cell
     }
 
-    impl<T> ::kinds::Sync for Key<T> { }
+    unsafe impl<T> ::kinds::Sync for Key<T> { }
 
     #[doc(hidden)]
     impl<T> Key<T> {
@@ -412,7 +412,7 @@ mod imp {
         pub os: OsStaticKey,
     }
 
-    impl<T> ::kinds::Sync for Key<T> { }
+    unsafe impl<T> ::kinds::Sync for Key<T> { }
 
     struct Value<T: 'static> {
         key: &'static Key<T>,
diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs
index 83e61373dd1..d7ea163cc80 100644
--- a/src/libstd/thread_local/scoped.rs
+++ b/src/libstd/thread_local/scoped.rs
@@ -202,7 +202,7 @@ mod imp {
     #[doc(hidden)]
     pub struct KeyInner<T> { pub inner: UnsafeCell<*mut T> }
 
-    #[cfg(not(stage0))] impl<T> ::kinds::Sync for KeyInner<T> { }
+    unsafe impl<T> ::kinds::Sync for KeyInner<T> { }
 
     #[doc(hidden)]
     impl<T> KeyInner<T> {
@@ -224,7 +224,7 @@ mod imp {
         pub marker: marker::InvariantType<T>,
     }
 
-    #[cfg(not(stage0))] impl<T> ::kinds::Sync for KeyInner<T> { }
+    unsafe impl<T> ::kinds::Sync for KeyInner<T> { }
 
     #[doc(hidden)]
     impl<T> KeyInner<T> {