diff options
Diffstat (limited to 'src/libstd/arc.rs')
| -rw-r--r-- | src/libstd/arc.rs | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 4ffe7245113..60db62ce01a 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -1,6 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; +// tjc: forbid deprecated modes again after snap /** * Concurrency-enabled mechanisms for sharing mutable and/or immutable state * between tasks. @@ -12,14 +11,9 @@ use private::{SharedMutableState, shared_mutable_state, use sync::{Mutex, mutex_with_condvars, RWlock, rwlock_with_condvars}; -export ARC, clone, get; -export Condvar; -export MutexARC, mutex_arc_with_condvars, unwrap_mutex_arc; -export RWARC, rw_arc_with_condvars, RWWriteMode, RWReadMode; -export unwrap_rw_arc; /// As sync::condvar, a mechanism for unlock-and-descheduling and signalling. -struct Condvar { is_mutex: bool, failed: &mut bool, cond: &sync::Condvar } +pub struct Condvar { is_mutex: bool, failed: &mut bool, cond: &sync::Condvar } impl &Condvar { /// Atomically exit the associated ARC and block until a signal is sent. @@ -72,7 +66,7 @@ impl &Condvar { struct ARC<T: Const Send> { x: SharedMutableState<T> } /// Create an atomically reference counted wrapper. -fn ARC<T: Const Send>(+data: T) -> ARC<T> { +pub fn ARC<T: Const Send>(data: T) -> ARC<T> { ARC { x: unsafe { shared_mutable_state(move data) } } } @@ -80,7 +74,7 @@ fn ARC<T: Const Send>(+data: T) -> ARC<T> { * Access the underlying data in an atomically reference counted * wrapper. */ -fn get<T: Const Send>(rc: &a/ARC<T>) -> &a/T { +pub fn get<T: Const Send>(rc: &a/ARC<T>) -> &a/T { unsafe { get_shared_immutable_state(&rc.x) } } @@ -91,7 +85,7 @@ fn get<T: Const Send>(rc: &a/ARC<T>) -> &a/T { * object. However, one of the `arc` objects can be sent to another task, * allowing them to share the underlying data. */ -fn clone<T: Const Send>(rc: &ARC<T>) -> ARC<T> { +pub fn clone<T: Const Send>(rc: &ARC<T>) -> ARC<T> { ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } } } @@ -104,7 +98,7 @@ fn clone<T: Const Send>(rc: &ARC<T>) -> ARC<T> { * unwrap from a task that holds another reference to the same ARC; it is * guaranteed to deadlock. */ -fn unwrap<T: Const Send>(+rc: ARC<T>) -> T { +fn unwrap<T: Const Send>(rc: ARC<T>) -> T { let ARC { x: x } <- rc; unsafe { unwrap_shared_mutable_state(move x) } } @@ -119,14 +113,14 @@ struct MutexARCInner<T: Send> { lock: Mutex, failed: bool, data: T } struct MutexARC<T: Send> { x: SharedMutableState<MutexARCInner<T>> } /// Create a mutex-protected ARC with the supplied data. -fn MutexARC<T: Send>(+user_data: T) -> MutexARC<T> { +pub fn MutexARC<T: Send>(user_data: T) -> MutexARC<T> { mutex_arc_with_condvars(move user_data, 1) } /** * Create a mutex-protected ARC with the supplied data and a specified number * of condvars (as sync::mutex_with_condvars). */ -fn mutex_arc_with_condvars<T: Send>(+user_data: T, +pub fn mutex_arc_with_condvars<T: Send>(user_data: T, num_condvars: uint) -> MutexARC<T> { let data = MutexARCInner { lock: mutex_with_condvars(num_condvars), @@ -197,7 +191,7 @@ impl<T: Send> &MutexARC<T> { * Will additionally fail if another task has failed while accessing the arc. */ // FIXME(#2585) make this a by-move method on the arc -fn unwrap_mutex_arc<T: Send>(+arc: MutexARC<T>) -> T { +pub fn unwrap_mutex_arc<T: Send>(arc: MutexARC<T>) -> T { let MutexARC { x: x } <- arc; let inner = unsafe { unwrap_shared_mutable_state(move x) }; let MutexARCInner { failed: failed, data: data, _ } <- inner; @@ -253,14 +247,14 @@ struct RWARC<T: Const Send> { } /// Create a reader/writer ARC with the supplied data. -fn RWARC<T: Const Send>(+user_data: T) -> RWARC<T> { +pub fn RWARC<T: Const Send>(user_data: T) -> RWARC<T> { rw_arc_with_condvars(move user_data, 1) } /** * Create a reader/writer ARC with the supplied data and a specified number * of condvars (as sync::rwlock_with_condvars). */ -fn rw_arc_with_condvars<T: Const Send>(+user_data: T, +pub fn rw_arc_with_condvars<T: Const Send>(user_data: T, num_condvars: uint) -> RWARC<T> { let data = RWARCInner { lock: rwlock_with_condvars(num_condvars), @@ -340,7 +334,7 @@ impl<T: Const Send> &RWARC<T> { * } * ~~~ */ - fn write_downgrade<U>(blk: fn(+v: RWWriteMode<T>) -> U) -> U { + fn write_downgrade<U>(blk: fn(v: RWWriteMode<T>) -> U) -> U { let state = unsafe { get_shared_mutable_state(&self.x) }; do borrow_rwlock(state).write_downgrade |write_mode| { check_poison(false, state.failed); @@ -350,7 +344,7 @@ impl<T: Const Send> &RWARC<T> { } /// To be called inside of the write_downgrade block. - fn downgrade(+token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> { + fn downgrade(token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> { // The rwlock should assert that the token belongs to us for us. let state = unsafe { get_shared_immutable_state(&self.x) }; let RWWriteMode((data, t, _poison)) <- token; @@ -375,7 +369,7 @@ impl<T: Const Send> &RWARC<T> { * in write mode. */ // FIXME(#2585) make this a by-move method on the arc -fn unwrap_rw_arc<T: Const Send>(+arc: RWARC<T>) -> T { +pub fn unwrap_rw_arc<T: Const Send>(arc: RWARC<T>) -> T { let RWARC { x: x, _ } <- arc; let inner = unsafe { unwrap_shared_mutable_state(move x) }; let RWARCInner { failed: failed, data: data, _ } <- inner; @@ -396,10 +390,10 @@ fn borrow_rwlock<T: Const Send>(state: &r/mut RWARCInner<T>) -> &r/RWlock { // FIXME (#3154) ice with struct/&<T> prevents these from being structs. /// The "write permission" token used for RWARC.write_downgrade(). -enum RWWriteMode<T: Const Send> = +pub enum RWWriteMode<T: Const Send> = (&mut T, sync::RWlockWriteMode, PoisonOnFail); /// The "read permission" token used for RWARC.write_downgrade(). -enum RWReadMode<T:Const Send> = (&T, sync::RWlockReadMode); +pub enum RWReadMode<T:Const Send> = (&T, sync::RWlockReadMode); impl<T: Const Send> &RWWriteMode<T> { /// Access the pre-downgrade RWARC in write mode. @@ -648,7 +642,7 @@ mod tests { let mut children = ~[]; for 5.times { let arc3 = ~arc.clone(); - do task::task().future_result(|+r| vec::push(children, r)).spawn { + do task::task().future_result(|+r| children.push(r)).spawn { do arc3.read |num| { assert *num >= 0; } @@ -676,7 +670,7 @@ mod tests { let mut reader_convos = ~[]; for 10.times { let ((rc1,rp1),(rc2,rp2)) = (pipes::stream(),pipes::stream()); - vec::push(reader_convos, (rc1,rp2)); + reader_convos.push((rc1,rp2)); let arcn = ~arc.clone(); do task::spawn { rp1.recv(); // wait for downgrader to give go-ahead @@ -719,7 +713,7 @@ mod tests { // send to other readers for vec::each(reader_convos) |x| { match *x { - (rc, _) => rc.send(()), + (ref rc, _) => rc.send(()), } } } @@ -728,7 +722,7 @@ mod tests { // complete handshake with other readers for vec::each(reader_convos) |x| { match *x { - (_, rp) => rp.recv(), + (_, ref rp) => rp.recv(), } } wc1.send(()); // tell writer to try again |
