diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 44e7291150ef9e0a9c27567a08ab91828a3b27a9..f4338815f759bcd7cd91eb1c30ec020ddf2e615e 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -180,12 +180,12 @@ mod tests { fn malloc(n: uint) -> CVec { unsafe { - let mem = libc::malloc(n as libc::size_t); - if mem.is_null() { ::alloc::oom() } + let mem = ptr::Unique(libc::malloc(n as libc::size_t)); + if mem.0.is_null() { ::alloc::oom() } - CVec::new_with_dtor(mem as *mut u8, + CVec::new_with_dtor(mem.0 as *mut u8, n, - move|| { libc::free(mem as *mut libc::c_void); }) + move|| { libc::free(mem.0 as *mut libc::c_void); }) } } diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 6573d9273ceffd9fb91e62f33abf4a314b1bf0d2..6cdb199819aff60f61a996ad3426f503c621738f 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use kinds::{Send, Sync}; use sync::{Mutex, Condvar}; /// A barrier enables multiple tasks to synchronize the beginning @@ -35,12 +36,18 @@ pub struct Barrier { num_threads: uint, } +unsafe impl Send for Barrier {} +unsafe impl Sync for Barrier {} + // The inner state of a double barrier struct BarrierState { count: uint, generation_id: uint, } +unsafe impl Send for BarrierState {} +unsafe impl Sync for BarrierState {} + impl Barrier { /// Create a new barrier that can block a given number of threads. /// diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index be27c06b83cd306953e9ac864a57fd72261df73b..f1940bfd829b769934d46c33068f2420f2634cf8 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -58,6 +58,9 @@ /// ``` pub struct Condvar { inner: Box } +unsafe impl Send for Condvar {} +unsafe impl Sync for Condvar {} + /// Statically allocated condition variables. /// /// This structure is identical to `Condvar` except that it is suitable for use @@ -75,6 +78,9 @@ pub struct StaticCondvar { mutex: AtomicUint, } +unsafe impl Send for StaticCondvar {} +unsafe impl Sync for StaticCondvar {} + /// Constant initializer for a statically allocated condition variable. pub const CONDVAR_INIT: StaticCondvar = StaticCondvar { inner: sys::CONDVAR_INIT, diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index fbbbb3e77a40785cc604e21d9c3a83fd8932feae..4d2fbfc4055f4163b5df12e0f63b9b1f3517c7d0 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -284,6 +284,11 @@ mod test { use thread::Thread; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; + struct Packet(Arc<(Mutex, Condvar)>); + + unsafe impl Send for Packet {} + unsafe impl Sync for Packet {} + #[test] fn smoke() { let m = Mutex::new(()); @@ -343,19 +348,19 @@ fn try_lock() { #[test] fn test_mutex_arc_condvar() { - let arc = Arc::new((Mutex::new(false), Condvar::new())); - let arc2 = arc.clone(); + let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); + let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); spawn(move|| { // wait until parent gets in rx.recv(); - let &(ref lock, ref cvar) = &*arc2; + let &(ref lock, ref cvar) = &*packet2.0; let mut lock = lock.lock(); *lock = true; cvar.notify_one(); }); - let &(ref lock, ref cvar) = &*arc; + let &(ref lock, ref cvar) = &*packet.0; let lock = lock.lock(); tx.send(()); assert!(!*lock); @@ -367,20 +372,20 @@ fn test_mutex_arc_condvar() { #[test] #[should_fail] fn test_arc_condvar_poison() { - let arc = Arc::new((Mutex::new(1i), Condvar::new())); - let arc2 = arc.clone(); + let packet = Packet(Arc::new((Mutex::new(1i), Condvar::new()))); + let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); spawn(move|| { rx.recv(); - let &(ref lock, ref cvar) = &*arc2; + let &(ref lock, ref cvar) = &*packet2.0; let _g = lock.lock(); cvar.notify_one(); // Parent should fail when it wakes up. panic!(); }); - let &(ref lock, ref cvar) = &*arc; + let &(ref lock, ref cvar) = &*packet.0; let lock = lock.lock(); tx.send(()); while *lock == 1 { diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 3f177a42f4471af71af98129cda5f7e8086c1ae6..76d05d9bfd419ad796ffb8f4ad4d050c822b0a13 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -60,6 +60,9 @@ pub struct RWLock { data: UnsafeCell, } +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + /// Structure representing a statically allocated RWLock. /// /// This structure is intended to be used inside of a `static` and will provide @@ -88,6 +91,9 @@ pub struct StaticRWLock { poison: UnsafeCell, } +unsafe impl Send for StaticRWLock {} +unsafe impl Sync for StaticRWLock {} + /// Constant initialization for a statically-initialized rwlock. pub const RWLOCK_INIT: StaticRWLock = StaticRWLock { inner: sys::RWLOCK_INIT,