diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-02 08:54:58 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-02 08:54:58 -0800 |
| commit | 5696ea58946f077f815dc5f74b883cf948c7e1ea (patch) | |
| tree | 0ecc90224cb9e0d68bf276ebd447d61a6bd72a59 /src/libstd/sync | |
| parent | 71b46b18a274edc7f7fb60b490e5ebbb9c911462 (diff) | |
| parent | 76e3bc23388e268438e4318b0580149619a9d1ac (diff) | |
| download | rust-5696ea58946f077f815dc5f74b883cf948c7e1ea.tar.gz rust-5696ea58946f077f815dc5f74b883cf948c7e1ea.zip | |
rollup merge of #20157: alexcrichton/issue-20068
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/atomic.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/barrier.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sync/condvar.rs | 21 | ||||
| -rw-r--r-- | src/libstd/sync/future.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sync/mutex.rs | 22 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sync/poison.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sync/semaphore.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sync/task_pool.rs | 8 |
10 files changed, 59 insertions, 45 deletions
diff --git a/src/libstd/sync/atomic.rs b/src/libstd/sync/atomic.rs index 18c917aca8a..a88932f21cb 100644 --- a/src/libstd/sync/atomic.rs +++ b/src/libstd/sync/atomic.rs @@ -180,7 +180,7 @@ impl<T: Send> Drop for AtomicOption<T> { #[cfg(test)] mod test { - use prelude::{Some, None}; + use prelude::v1::*; use super::*; #[test] diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 4091f0df395..1c73bf7cf35 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -89,10 +89,11 @@ impl Barrier { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use sync::{Arc, Barrier}; - use comm::Empty; + use comm::{channel, Empty}; + use thread::Thread; #[test] fn test_barrier() { @@ -102,10 +103,10 @@ mod tests { for _ in range(0u, 9) { let c = barrier.clone(); let tx = tx.clone(); - spawn(move|| { + Thread::spawn(move|| { c.wait(); tx.send(true); - }); + }).detach(); } // At this point, all spawned tasks should be blocked, diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 15faf5be258..df3f2e5cf62 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use sync::atomic::{mod, AtomicUint}; use sync::poison::{mod, LockResult}; @@ -279,11 +279,13 @@ impl StaticCondvar { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; - use time::Duration; + use comm::channel; use super::{StaticCondvar, CONDVAR_INIT}; use sync::{StaticMutex, MUTEX_INIT, Condvar, Mutex, Arc}; + use thread::Thread; + use time::Duration; #[test] fn smoke() { @@ -305,8 +307,8 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; static M: StaticMutex = MUTEX_INIT; - let g = M.lock().unwrap(); - spawn(move|| { + let mut g = M.lock().unwrap(); + let _t = Thread::spawn(move|| { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -324,7 +326,7 @@ mod tests { for _ in range(0, N) { let data = data.clone(); let tx = tx.clone(); - spawn(move|| { + Thread::spawn(move|| { let &(ref lock, ref cond) = &*data; let mut cnt = lock.lock().unwrap(); *cnt += 1; @@ -335,7 +337,7 @@ mod tests { cnt = cond.wait(cnt).unwrap(); } tx.send(()); - }); + }).detach(); } drop(tx); @@ -359,7 +361,7 @@ mod tests { let g = M.lock().unwrap(); let (g, success) = C.wait_timeout(g, Duration::nanoseconds(1000)).unwrap(); assert!(!success); - spawn(move|| { + let _t = Thread::spawn(move || { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -377,7 +379,7 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; let mut g = M1.lock().unwrap(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M1.lock().unwrap(); C.notify_one(); }); @@ -385,6 +387,5 @@ mod tests { drop(g); C.wait(M2.lock().unwrap()).unwrap(); - } } diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index 51899a87a32..a0e7236b8d2 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -150,9 +150,10 @@ impl<A:Send> Future<A> { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; + use comm::channel; use sync::Future; - use task; + use thread::Thread; #[test] fn test_from_value() { @@ -210,7 +211,7 @@ mod test { let expected = "schlorf"; let (tx, rx) = channel(); let f = Future::spawn(move|| { expected }); - task::spawn(move|| { + let _t = Thread::spawn(move|| { let mut f = f; tx.send(f.get()); }); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 52004bb4a8f..98425f26c1a 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use cell::UnsafeCell; use kinds::marker; +use ops::{Deref, DerefMut}; use sync::poison::{mod, TryLockError, TryLockResult, LockResult}; use sys_common::mutex as sys; @@ -47,6 +48,8 @@ use sys_common::mutex as sys; /// ```rust /// use std::sync::{Arc, Mutex}; /// use std::thread::Thread; +/// use std::comm::channel; +/// /// const N: uint = 10; /// /// // Spawn a few threads to increment a shared variable (non-atomically), and @@ -320,10 +323,11 @@ pub fn guard_poison<'a, T>(guard: &MutexGuard<'a, T>) -> &'a poison::Flag { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; - use thread::Thread; + use comm::channel; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; + use thread::Thread; struct Packet<T>(Arc<(Mutex<T>, Condvar)>); @@ -366,9 +370,9 @@ mod test { let (tx, rx) = channel(); for _ in range(0, K) { let tx2 = tx.clone(); - spawn(move|| { inc(); tx2.send(()); }); + Thread::spawn(move|| { inc(); tx2.send(()); }).detach(); let tx2 = tx.clone(); - spawn(move|| { inc(); tx2.send(()); }); + Thread::spawn(move|| { inc(); tx2.send(()); }).detach(); } drop(tx); @@ -392,7 +396,7 @@ mod test { let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { // wait until parent gets in rx.recv(); let &(ref lock, ref cvar) = &*packet2.0; @@ -416,7 +420,7 @@ mod test { let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move || -> () { rx.recv(); let &(ref lock, ref cvar) = &*packet2.0; let _g = lock.lock().unwrap(); @@ -457,9 +461,9 @@ mod test { let arc = Arc::new(Mutex::new(1i)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let lock = arc2.lock().unwrap(); - let lock2 = lock.deref().lock().unwrap(); + let lock2 = lock.lock().unwrap(); assert_eq!(*lock2, 1); tx.send(()); }); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 4d9fbb59908..fe25eca03d7 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -122,10 +122,11 @@ impl Once { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use thread::Thread; use super::{ONCE_INIT, Once}; + use comm::channel; #[test] fn smoke_once() { @@ -145,7 +146,7 @@ mod test { let (tx, rx) = channel(); for _ in range(0u, 10) { let tx = tx.clone(); - spawn(move|| { + Thread::spawn(move|| { for _ in range(0u, 4) { Thread::yield_now() } unsafe { O.doit(|| { @@ -155,7 +156,7 @@ mod test { assert!(run); } tx.send(()); - }); + }).detach(); } unsafe { diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index edf16d99f49..6e4df118209 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use cell::UnsafeCell; use error::FromError; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 7f3c77c97ad..efdd894a806 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; use cell::UnsafeCell; use kinds::marker; +use ops::{Deref, DerefMut}; use sync::poison::{mod, LockResult, TryLockError, TryLockResult}; use sys_common::rwlock as sys; @@ -355,9 +356,10 @@ impl<'a, T> Drop for RWLockWriteGuard<'a, T> { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use rand::{mod, Rng}; + use comm::channel; use thread::Thread; use sync::{Arc, RWLock, StaticRWLock, RWLOCK_INIT}; @@ -389,7 +391,7 @@ mod tests { let (tx, rx) = channel::<()>(); for _ in range(0, N) { let tx = tx.clone(); - spawn(move|| { + Thread::spawn(move|| { let mut rng = rand::thread_rng(); for _ in range(0, M) { if rng.gen_weighted_bool(N) { @@ -399,7 +401,7 @@ mod tests { } } drop(tx); - }); + }).detach(); } drop(tx); let _ = rx.recv_opt(); diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index e3b683a6ccb..a283626a408 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -104,10 +104,12 @@ impl<'a> Drop for SemaphoreGuard<'a> { #[cfg(test)] mod tests { - use prelude::*; + use prelude::v1::*; use sync::Arc; use super::Semaphore; + use comm::channel; + use thread::Thread; #[test] fn test_sem_acquire_release() { @@ -127,7 +129,7 @@ mod tests { fn test_sem_as_mutex() { let s = Arc::new(Semaphore::new(1)); let s2 = s.clone(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = s2.access(); }); let _g = s.access(); @@ -139,7 +141,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - spawn(move|| { + let _t = Thread::spawn(move|| { s2.acquire(); tx.send(()); }); @@ -150,7 +152,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - spawn(move|| { + let _t = Thread::spawn(move|| { s2.release(); let _ = rx.recv(); }); @@ -166,7 +168,7 @@ mod tests { let s2 = s.clone(); let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = s2.access(); let _ = rx2.recv(); tx1.send(()); @@ -183,11 +185,11 @@ mod tests { let (tx, rx) = channel(); { let _g = s.access(); - spawn(move|| { + Thread::spawn(move|| { tx.send(()); drop(s2.access()); tx.send(()); - }); + }).detach(); rx.recv(); // wait for child to come alive } rx.recv(); // wait for child to be done diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index ee534f6cdde..63c10c18046 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -53,8 +53,9 @@ impl<'a> Drop for Sentinel<'a> { /// # Example /// /// ```rust -/// # use std::sync::TaskPool; -/// # use std::iter::AdditiveIterator; +/// use std::sync::TaskPool; +/// use std::iter::AdditiveIterator; +/// use std::comm::channel; /// /// let pool = TaskPool::new(4u); /// @@ -131,8 +132,9 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) { #[cfg(test)] mod test { - use prelude::*; + use prelude::v1::*; use super::*; + use comm::channel; const TEST_TASKS: uint = 4u; |
