diff --git a/src/libsync/arc.rs b/src/libsync/arc.rs index db4260a30ee1..17a35f331705 100644 --- a/src/libsync/arc.rs +++ b/src/libsync/arc.rs @@ -49,14 +49,15 @@ use std::kinds::marker; use std::sync::arc::UnsafeArc; use std::task; -/// As sync::condvar, a mechanism for unlock-and-descheduling and signaling. -pub struct Condvar<'a> { +/// As sync::condvar, a mechanism for unlock-and-descheduling and +/// signaling, for use with the Arc types. +pub struct ArcCondvar<'a> { priv is_mutex: bool, priv failed: &'a bool, priv cond: &'a sync::Condvar<'a> } -impl<'a> Condvar<'a> { +impl<'a> ArcCondvar<'a> { /// Atomically exit the associated Arc and block until a signal is sent. #[inline] pub fn wait(&self) { self.wait_on(0) } @@ -219,14 +220,14 @@ impl MutexArc { /// As access(), but with a condvar, as sync::mutex.lock_cond(). #[inline] - pub fn access_cond(&self, blk: |x: &mut T, c: &Condvar| -> U) -> U { + pub fn access_cond(&self, blk: |x: &mut T, c: &ArcCondvar| -> U) -> U { let state = self.x.get(); unsafe { (&(*state).lock).lock_cond(|cond| { check_poison(true, (*state).failed); let _z = PoisonOnFail::new(&mut (*state).failed); blk(&mut (*state).data, - &Condvar {is_mutex: true, + &ArcCondvar {is_mutex: true, failed: &(*state).failed, cond: cond }) }) @@ -345,7 +346,7 @@ impl RWArc { /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline] pub fn write_cond(&self, - blk: |x: &mut T, c: &Condvar| -> U) + blk: |x: &mut T, c: &ArcCondvar| -> U) -> U { unsafe { let state = self.x.get(); @@ -353,7 +354,7 @@ impl RWArc { check_poison(false, (*state).failed); let _z = PoisonOnFail::new(&mut (*state).failed); blk(&mut (*state).data, - &Condvar {is_mutex: false, + &ArcCondvar {is_mutex: false, failed: &(*state).failed, cond: cond}) }) @@ -481,7 +482,7 @@ impl<'a, T:Freeze + Send> RWWriteMode<'a, T> { /// Access the pre-downgrade RWArc in write mode with a condvar. pub fn write_cond(&mut self, - blk: |x: &mut T, c: &Condvar| -> U) + blk: |x: &mut T, c: &ArcCondvar| -> U) -> U { match *self { RWWriteMode { @@ -491,7 +492,7 @@ impl<'a, T:Freeze + Send> RWWriteMode<'a, T> { } => { token.write_cond(|cond| { unsafe { - let cvar = Condvar { + let cvar = ArcCondvar { is_mutex: false, failed: &*poison.flag, cond: cond @@ -915,7 +916,7 @@ mod tests { // rwarc gives us extra shared state to help check for the race. // If you want to see this test fail, go to sync.rs and replace the // line in RWLock::write_cond() that looks like: - // "blk(&Condvar { order: opt_lock, ..*cond })" + // "blk(&ArcCondvar { order: opt_lock, ..*cond })" // with just "blk(cond)". let x = RWArc::new(true); let (wp, wc) = Chan::new(); diff --git a/src/libsync/lib.rs b/src/libsync/lib.rs index d96685c7f553..80abcce0df35 100644 --- a/src/libsync/lib.rs +++ b/src/libsync/lib.rs @@ -17,7 +17,7 @@ #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; -pub use arc::{Arc, MutexArc, RWArc, RWWriteMode, RWReadMode, Condvar, CowArc}; +pub use arc::{Arc, MutexArc, RWArc, RWWriteMode, RWReadMode, ArcCondvar, CowArc}; pub use sync::{Mutex, RWLock, Condvar, Semaphore, RWLockWriteMode, RWLockReadMode, Barrier, one, mutex}; pub use comm::{DuplexStream, SyncChan, SyncPort, rendezvous};