Skip to content

Commit c6ab9a6

Browse files
committed
Don't use NoSend/NoSync in libstd
1 parent bb04121 commit c6ab9a6

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
#![feature(slicing_syntax, unboxed_closures)]
111111
#![feature(box_syntax)]
112112
#![feature(old_impl_check)]
113+
#![feature(optin_builtin_traits)]
113114
#![allow(unknown_features)] #![feature(int_uint)]
114115

115116
// Don't link to std. We are std.

src/libstd/sync/mpsc/blocking.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use thread::Thread;
1414
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
1515
use sync::Arc;
1616
use marker::{Sync, Send};
17+
#[cfg(stage0)] // NOTE remove use after next snapshot
1718
use marker::{NoSend, NoSync};
1819
use mem;
1920
use clone::Clone;
@@ -31,12 +32,25 @@ pub struct SignalToken {
3132
inner: Arc<Inner>,
3233
}
3334

35+
#[cfg(stage0)] // NOTE remove impl after next snapshot
3436
pub struct WaitToken {
3537
inner: Arc<Inner>,
3638
no_send: NoSend,
3739
no_sync: NoSync,
3840
}
3941

42+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
43+
pub struct WaitToken {
44+
inner: Arc<Inner>,
45+
}
46+
47+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
48+
impl !Send for WaitToken {}
49+
50+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
51+
impl !Sync for WaitToken {}
52+
53+
#[cfg(stage0)] // NOTE remove impl after next snapshot
4054
pub fn tokens() -> (WaitToken, SignalToken) {
4155
let inner = Arc::new(Inner {
4256
thread: Thread::current(),
@@ -53,6 +67,21 @@ pub fn tokens() -> (WaitToken, SignalToken) {
5367
(wait_token, signal_token)
5468
}
5569

70+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
71+
pub fn tokens() -> (WaitToken, SignalToken) {
72+
let inner = Arc::new(Inner {
73+
thread: Thread::current(),
74+
woken: ATOMIC_BOOL_INIT,
75+
});
76+
let wait_token = WaitToken {
77+
inner: inner.clone(),
78+
};
79+
let signal_token = SignalToken {
80+
inner: inner
81+
};
82+
(wait_token, signal_token)
83+
}
84+
5685
impl SignalToken {
5786
pub fn signal(&self) -> bool {
5887
let wake = !self.inner.woken.compare_and_swap(false, true, Ordering::SeqCst);

src/libstd/sync/mpsc/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,24 @@ unsafe impl<T:Send> Send for Sender<T> { }
370370
/// The sending-half of Rust's synchronous channel type. This half can only be
371371
/// owned by one task, but it can be cloned to send to other tasks.
372372
#[stable]
373+
#[cfg(stage0)] // NOTE remove impl after next snapshot
373374
pub struct SyncSender<T> {
374375
inner: Arc<RacyCell<sync::Packet<T>>>,
375376
// can't share in an arc
376377
_marker: marker::NoSync,
377378
}
378379

380+
/// The sending-half of Rust's synchronous channel type. This half can only be
381+
/// owned by one task, but it can be cloned to send to other tasks.
382+
#[stable]
383+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
384+
pub struct SyncSender<T> {
385+
inner: Arc<RacyCell<sync::Packet<T>>>,
386+
}
387+
388+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
389+
impl<T> !marker::Sync for SyncSender<T> {}
390+
379391
/// An error returned from the `send` function on channels.
380392
///
381393
/// A `send` operation can only fail if the receiving end of a channel is
@@ -677,10 +689,16 @@ impl<T: Send> Drop for Sender<T> {
677689
////////////////////////////////////////////////////////////////////////////////
678690

679691
impl<T: Send> SyncSender<T> {
692+
#[cfg(stage0)] // NOTE remove impl after next snapshot
680693
fn new(inner: Arc<RacyCell<sync::Packet<T>>>) -> SyncSender<T> {
681694
SyncSender { inner: inner, _marker: marker::NoSync }
682695
}
683696

697+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
698+
fn new(inner: Arc<RacyCell<sync::Packet<T>>>) -> SyncSender<T> {
699+
SyncSender { inner: inner }
700+
}
701+
684702
/// Sends a value on this synchronous channel.
685703
///
686704
/// This function will *block* until space in the internal buffer becomes

src/libstd/sync/mpsc/select.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,26 @@ use sync::mpsc::blocking::{self, SignalToken};
6666

6767
/// The "receiver set" of the select interface. This structure is used to manage
6868
/// a set of receivers which are being selected over.
69+
#[cfg(stage0)] // NOTE remove impl after next snapshot
6970
pub struct Select {
7071
head: *mut Handle<'static, ()>,
7172
tail: *mut Handle<'static, ()>,
7273
next_id: Cell<uint>,
7374
marker1: marker::NoSend,
7475
}
7576

77+
/// The "receiver set" of the select interface. This structure is used to manage
78+
/// a set of receivers which are being selected over.
79+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
80+
pub struct Select {
81+
head: *mut Handle<'static, ()>,
82+
tail: *mut Handle<'static, ()>,
83+
next_id: Cell<uint>,
84+
}
85+
86+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
87+
impl !marker::Send for Select {}
88+
7689
/// A handle to a receiver which is currently a member of a `Select` set of
7790
/// receivers. This handle is used to keep the receiver in the set as well as
7891
/// interact with the underlying receiver.
@@ -113,6 +126,7 @@ impl Select {
113126
///
114127
/// Usage of this struct directly can sometimes be burdensome, and usage is
115128
/// rather much easier through the `select!` macro.
129+
#[cfg(stage0)] // NOTE remove impl after next snapshot
116130
pub fn new() -> Select {
117131
Select {
118132
marker1: marker::NoSend,
@@ -122,6 +136,20 @@ impl Select {
122136
}
123137
}
124138

139+
/// Creates a new selection structure. This set is initially empty and
140+
/// `wait` will panic!() if called.
141+
///
142+
/// Usage of this struct directly can sometimes be burdensome, and usage is
143+
/// rather much easier through the `select!` macro.
144+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
145+
pub fn new() -> Select {
146+
Select {
147+
head: 0 as *mut Handle<'static, ()>,
148+
tail: 0 as *mut Handle<'static, ()>,
149+
next_id: Cell::new(1),
150+
}
151+
}
152+
125153
/// Creates a new handle into this receiver set for a new receiver. Note
126154
/// that this does *not* add the receiver to the receiver set, for that you
127155
/// must call the `add` method on the handle itself.

src/libstd/sync/mutex.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ unsafe impl Sync for StaticMutex {}
160160
/// Deref and DerefMut implementations
161161
#[must_use]
162162
#[stable]
163+
#[cfg(stage0)] // NOTE remove impl after next snapshot
163164
pub struct MutexGuard<'a, T: 'a> {
164165
// funny underscores due to how Deref/DerefMut currently work (they
165166
// disregard field privacy).
@@ -169,6 +170,25 @@ pub struct MutexGuard<'a, T: 'a> {
169170
__marker: marker::NoSend,
170171
}
171172

173+
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
174+
/// dropped (falls out of scope), the lock will be unlocked.
175+
///
176+
/// The data protected by the mutex can be access through this guard via its
177+
/// Deref and DerefMut implementations
178+
#[must_use]
179+
#[stable]
180+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
181+
pub struct MutexGuard<'a, T: 'a> {
182+
// funny underscores due to how Deref/DerefMut currently work (they
183+
// disregard field privacy).
184+
__lock: &'a StaticMutex,
185+
__data: &'a UnsafeCell<T>,
186+
__poison: poison::Guard,
187+
}
188+
189+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
190+
impl<'a, T> !marker::Send for MutexGuard<'a, T> {}
191+
172192
/// Static initialization of a mutex. This constant can be used to initialize
173193
/// other mutex constants.
174194
#[unstable = "may be merged with Mutex in the future"]
@@ -279,6 +299,7 @@ impl StaticMutex {
279299
}
280300

281301
impl<'mutex, T> MutexGuard<'mutex, T> {
302+
#[cfg(stage0)] // NOTE remove afte next snapshot
282303
fn new(lock: &'mutex StaticMutex, data: &'mutex UnsafeCell<T>)
283304
-> LockResult<MutexGuard<'mutex, T>> {
284305
poison::map_result(lock.poison.borrow(), |guard| {
@@ -290,6 +311,18 @@ impl<'mutex, T> MutexGuard<'mutex, T> {
290311
}
291312
})
292313
}
314+
315+
#[cfg(not(stage0))] // NOTE remove cfg afte next snapshot
316+
fn new(lock: &'mutex StaticMutex, data: &'mutex UnsafeCell<T>)
317+
-> LockResult<MutexGuard<'mutex, T>> {
318+
poison::map_result(lock.poison.borrow(), |guard| {
319+
MutexGuard {
320+
__lock: lock,
321+
__data: data,
322+
__poison: guard,
323+
}
324+
})
325+
}
293326
}
294327

295328
#[stable]

src/libstd/sync/rwlock.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,52 @@ pub const RW_LOCK_INIT: StaticRwLock = StaticRwLock {
110110
/// dropped.
111111
#[must_use]
112112
#[stable]
113+
#[cfg(stage0)] // NOTE remove impl after next snapshot
113114
pub struct RwLockReadGuard<'a, T: 'a> {
114115
__lock: &'a StaticRwLock,
115116
__data: &'a UnsafeCell<T>,
116117
__marker: marker::NoSend,
117118
}
118119

120+
/// RAII structure used to release the shared read access of a lock when
121+
/// dropped.
122+
#[must_use]
123+
#[stable]
124+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
125+
pub struct RwLockReadGuard<'a, T: 'a> {
126+
__lock: &'a StaticRwLock,
127+
__data: &'a UnsafeCell<T>,
128+
}
129+
130+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
131+
impl<'a, T> !marker::Send for RwLockReadGuard<'a, T> {}
132+
119133
/// RAII structure used to release the exclusive write access of a lock when
120134
/// dropped.
121135
#[must_use]
122136
#[stable]
137+
#[cfg(stage0)] // NOTE remove impl after next snapshot
123138
pub struct RwLockWriteGuard<'a, T: 'a> {
124139
__lock: &'a StaticRwLock,
125140
__data: &'a UnsafeCell<T>,
126141
__poison: poison::Guard,
127142
__marker: marker::NoSend,
128143
}
129144

145+
/// RAII structure used to release the exclusive write access of a lock when
146+
/// dropped.
147+
#[must_use]
148+
#[stable]
149+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
150+
pub struct RwLockWriteGuard<'a, T: 'a> {
151+
__lock: &'a StaticRwLock,
152+
__data: &'a UnsafeCell<T>,
153+
__poison: poison::Guard,
154+
}
155+
156+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
157+
impl<'a, T> !marker::Send for RwLockWriteGuard<'a, T> {}
158+
130159
impl<T: Send + Sync> RwLock<T> {
131160
/// Creates a new instance of an RwLock which is unlocked and read to go.
132161
#[stable]
@@ -303,6 +332,7 @@ impl StaticRwLock {
303332
}
304333

305334
impl<'rwlock, T> RwLockReadGuard<'rwlock, T> {
335+
#[cfg(stage0)] // NOTE remove impl after next snapshot
306336
fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
307337
-> LockResult<RwLockReadGuard<'rwlock, T>> {
308338
poison::map_result(lock.poison.borrow(), |_| {
@@ -313,8 +343,20 @@ impl<'rwlock, T> RwLockReadGuard<'rwlock, T> {
313343
}
314344
})
315345
}
346+
347+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
348+
fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
349+
-> LockResult<RwLockReadGuard<'rwlock, T>> {
350+
poison::map_result(lock.poison.borrow(), |_| {
351+
RwLockReadGuard {
352+
__lock: lock,
353+
__data: data,
354+
}
355+
})
356+
}
316357
}
317358
impl<'rwlock, T> RwLockWriteGuard<'rwlock, T> {
359+
#[cfg(stage0)] // NOTE remove impl after next snapshot
318360
fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
319361
-> LockResult<RwLockWriteGuard<'rwlock, T>> {
320362
poison::map_result(lock.poison.borrow(), |guard| {
@@ -326,6 +368,18 @@ impl<'rwlock, T> RwLockWriteGuard<'rwlock, T> {
326368
}
327369
})
328370
}
371+
372+
#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
373+
fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
374+
-> LockResult<RwLockWriteGuard<'rwlock, T>> {
375+
poison::map_result(lock.poison.borrow(), |guard| {
376+
RwLockWriteGuard {
377+
__lock: lock,
378+
__data: data,
379+
__poison: guard,
380+
}
381+
})
382+
}
329383
}
330384

331385
#[stable]

0 commit comments

Comments
 (0)