diff options
| author | Flavio Percoco <flaper87@gmail.com> | 2014-12-22 00:49:42 +0100 |
|---|---|---|
| committer | Flavio Percoco <flaper87@gmail.com> | 2014-12-26 17:26:33 +0100 |
| commit | f436f9ca2963e33cc41802370bb9c551c833970e (patch) | |
| tree | c79b09c0cb3024b389027fd2a501a44a0a1f9bb9 /src/libstd/sys | |
| parent | 686ce664da31f87b8d1c7377313f160d8fdcebe9 (diff) | |
| download | rust-f436f9ca2963e33cc41802370bb9c551c833970e.tar.gz rust-f436f9ca2963e33cc41802370bb9c551c833970e.zip | |
Make Send and Sync traits unsafe
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/common/helper_thread.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/common/mutex.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mutex.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/pipe.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tcp.rs | 6 |
6 files changed, 18 insertions, 10 deletions
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() } |
