diff options
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 | 18 | ||||
| -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/rwlock.rs | 14 | ||||
| -rw-r--r-- | src/libstd/sync/semaphore.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sync/task_pool.rs | 8 |
9 files changed, 59 insertions, 44 deletions
diff --git a/src/libstd/sync/atomic.rs b/src/libstd/sync/atomic.rs index 26778ef70b3..5d45836af80 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::*; + use prelude::v1::*; use super::*; #[test] diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 6cdb199819a..15a682ad3b8 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 f1940bfd829..984b895b31d 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::{mutex, StaticMutexGuard}; @@ -262,11 +262,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() { @@ -289,7 +291,7 @@ mod tests { static M: StaticMutex = MUTEX_INIT; let g = M.lock(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M.lock(); C.notify_one(); }); @@ -307,7 +309,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(); *cnt += 1; @@ -318,7 +320,7 @@ mod tests { cond.wait(&cnt); } tx.send(()); - }); + }).detach(); } drop(tx); @@ -341,7 +343,7 @@ mod tests { let g = M.lock(); assert!(!C.wait_timeout(&g, Duration::nanoseconds(1000))); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M.lock(); C.notify_one(); }); @@ -358,7 +360,7 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; let g = M1.lock(); - spawn(move|| { + let _t = Thread::spawn(move|| { let _g = M1.lock(); C.notify_one(); }); 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 4d2fbfc4055..87a02bd4ef5 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, AsMutexGuard}; use sys_common::mutex as sys; @@ -36,6 +37,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 @@ -279,10 +282,11 @@ impl Drop for StaticMutexGuard { #[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)>); @@ -325,9 +329,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); @@ -351,7 +355,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; @@ -376,7 +380,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(); @@ -413,9 +417,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(); - let lock2 = lock.deref().lock(); + let lock2 = lock.lock(); 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/rwlock.rs b/src/libstd/sync/rwlock.rs index 76d05d9bfd4..b316cd908b6 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use prelude::*; +use prelude::v1::*; -use kinds::marker; use cell::UnsafeCell; -use sys_common::rwlock as sys; +use kinds::marker; +use ops::{Deref, DerefMut}; use sync::poison; +use sys_common::rwlock as sys; /// A reader-writer lock /// @@ -359,9 +360,10 @@ impl Drop for StaticRWLockWriteGuard { #[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}; @@ -393,7 +395,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::task_rng(); for _ in range(0, M) { if rng.gen_weighted_bool(N) { @@ -403,7 +405,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 574b0f22bee..382caa2cf4a 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 366e4b7d35b..ce7e883e803 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; |
