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/comm | |
| parent | 686ce664da31f87b8d1c7377313f160d8fdcebe9 (diff) | |
Make Send and Sync traits unsafe
Diffstat (limited to 'src/libstd/comm')
| -rw-r--r-- | src/libstd/comm/blocking.rs | 5 | ||||
| -rw-r--r-- | src/libstd/comm/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/mpsc_queue.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/spsc_queue.rs | 4 | ||||
| -rw-r--r-- | src/libstd/comm/sync.rs | 9 |
5 files changed, 15 insertions, 11 deletions
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> { |
