diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 2349a0eec7f..75fdf0c3457 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -13,15 +13,16 @@ import sync; import sync::{Mutex, mutex, mutex_with_condvars, RWlock, rwlock, rwlock_with_condvars}; -export arc, clone, get; -export condvar, mutex_arc, mutex_arc_with_condvars, unwrap_mutex_arc; -export rw_arc, rw_arc_with_condvars, rw_write_mode, rw_read_mode; +export ARC, arc, clone, get; +export Condvar; +export MutexARC, mutex_arc, mutex_arc_with_condvars, unwrap_mutex_arc; +export RWARC, rw_arc, 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; } +struct Condvar { is_mutex: bool; failed: &mut bool; cond: &sync::Condvar; } -impl &condvar { +impl &Condvar { /// Atomically exit the associated ARC and block until a signal is sent. #[inline(always)] fn wait() { self.wait_on(0) } @@ -69,18 +70,18 @@ impl &condvar { ****************************************************************************/ /// An atomically reference counted wrapper for shared immutable state. -struct arc { x: SharedMutableState; } +struct ARC { x: SharedMutableState; } /// Create an atomically reference counted wrapper. -fn arc(+data: T) -> arc { - arc { x: unsafe { shared_mutable_state(data) } } +fn arc(+data: T) -> ARC { + ARC { x: unsafe { shared_mutable_state(data) } } } /** * Access the underlying data in an atomically reference counted * wrapper. */ -fn get(rc: &arc) -> &T { +fn get(rc: &ARC) -> &T { unsafe { get_shared_immutable_state(&rc.x) } } @@ -91,8 +92,8 @@ fn get(rc: &arc) -> &T { * object. However, one of the `arc` objects can be sent to another task, * allowing them to share the underlying data. */ -fn clone(rc: &arc) -> arc { - arc { x: unsafe { clone_shared_mutable_state(&rc.x) } } +fn clone(rc: &ARC) -> ARC { + ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } } } /** @@ -104,8 +105,8 @@ fn clone(rc: &arc) -> arc { * unwrap from a task that holds another reference to the same ARC; it is * guaranteed to deadlock. */ -fn unwrap(+rc: arc) -> T { - let arc { x: x } = rc; +fn unwrap(+rc: ARC) -> T { + let ARC { x: x } = rc; unsafe { unwrap_shared_mutable_state(x) } } @@ -114,12 +115,12 @@ fn unwrap(+rc: arc) -> T { ****************************************************************************/ #[doc(hidden)] -struct mutex_arc_inner { lock: Mutex; failed: bool; data: T; } +struct MutexARCInner { lock: Mutex; failed: bool; data: T; } /// An ARC with mutable data protected by a blocking mutex. -struct mutex_arc { x: SharedMutableState>; } +struct MutexARC { x: SharedMutableState>; } /// Create a mutex-protected ARC with the supplied data. -fn mutex_arc(+user_data: T) -> mutex_arc { +fn mutex_arc(+user_data: T) -> MutexARC { mutex_arc_with_condvars(user_data, 1) } /** @@ -127,19 +128,19 @@ fn mutex_arc(+user_data: T) -> mutex_arc { * of condvars (as sync::mutex_with_condvars). */ fn mutex_arc_with_condvars(+user_data: T, - num_condvars: uint) -> mutex_arc { + num_condvars: uint) -> MutexARC { let data = - mutex_arc_inner { lock: mutex_with_condvars(num_condvars), + MutexARCInner { lock: mutex_with_condvars(num_condvars), failed: false, data: user_data }; - mutex_arc { x: unsafe { shared_mutable_state(data) } } + MutexARC { x: unsafe { shared_mutable_state(data) } } } -impl &mutex_arc { +impl &MutexARC { /// Duplicate a mutex-protected ARC, as arc::clone. - fn clone() -> mutex_arc { + fn clone() -> MutexARC { // NB: Cloning the underlying mutex is not necessary. Its reference // count would be exactly the same as the shared state's. - mutex_arc { x: unsafe { clone_shared_mutable_state(&self.x) } } + MutexARC { x: unsafe { clone_shared_mutable_state(&self.x) } } } /** @@ -172,19 +173,19 @@ impl &mutex_arc { // unsafe. See borrow_rwlock, far below. do (&state.lock).lock { check_poison(true, state.failed); - let _z = poison_on_fail(&mut state.failed); + let _z = PoisonOnFail(&mut state.failed); blk(&mut state.data) } } /// As access(), but with a condvar, as sync::mutex.lock_cond(). #[inline(always)] - unsafe fn access_cond(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U { + unsafe fn access_cond(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U { let state = unsafe { get_shared_mutable_state(&self.x) }; do (&state.lock).lock_cond |cond| { check_poison(true, state.failed); - let _z = poison_on_fail(&mut state.failed); + let _z = PoisonOnFail(&mut state.failed); blk(&mut state.data, - &condvar { is_mutex: true, failed: &mut state.failed, + &Condvar { is_mutex: true, failed: &mut state.failed, cond: cond }) } } @@ -197,12 +198,12 @@ impl &mutex_arc { * 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(+arc: mutex_arc) -> T { - let mutex_arc { x: x } = arc; +fn unwrap_mutex_arc(+arc: MutexARC) -> T { + let MutexARC { x: x } = arc; let inner = unsafe { unwrap_shared_mutable_state(x) }; - let mutex_arc_inner { failed: failed, data: data, _ } = inner; + let MutexARCInner { failed: failed, data: data, _ } = inner; if failed { - fail ~"Can't unwrap poisoned mutex_arc - another task failed inside!" + fail ~"Can't unwrap poisoned MutexARC - another task failed inside!" } data } @@ -213,7 +214,7 @@ fn unwrap_mutex_arc(+arc: mutex_arc) -> T { fn check_poison(is_mutex: bool, failed: bool) { if failed { if is_mutex { - fail ~"Poisoned mutex_arc - another task failed inside!"; + fail ~"Poisoned MutexARC - another task failed inside!"; } else { fail ~"Poisoned rw_arc - another task failed inside!"; } @@ -221,7 +222,7 @@ fn check_poison(is_mutex: bool, failed: bool) { } #[doc(hidden)] -struct poison_on_fail { +struct PoisonOnFail { failed: &mut bool; new(failed: &mut bool) { self.failed = failed; } drop { @@ -235,20 +236,20 @@ struct poison_on_fail { ****************************************************************************/ #[doc(hidden)] -struct rw_arc_inner { lock: RWlock; failed: bool; data: T; } +struct RWARCInner { lock: RWlock; failed: bool; data: T; } /** * A dual-mode ARC protected by a reader-writer lock. The data can be accessed * mutably or immutably, and immutably-accessing tasks may run concurrently. * * Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested. */ -struct rw_arc { - x: SharedMutableState>; +struct RWARC { + x: SharedMutableState>; mut cant_nest: (); } /// Create a reader/writer ARC with the supplied data. -fn rw_arc(+user_data: T) -> rw_arc { +fn rw_arc(+user_data: T) -> RWARC { rw_arc_with_condvars(user_data, 1) } /** @@ -256,18 +257,18 @@ fn rw_arc(+user_data: T) -> rw_arc { * of condvars (as sync::rwlock_with_condvars). */ fn rw_arc_with_condvars(+user_data: T, - num_condvars: uint) -> rw_arc { + num_condvars: uint) -> RWARC { let data = - rw_arc_inner { lock: rwlock_with_condvars(num_condvars), - failed: false, data: user_data }; - rw_arc { x: unsafe { shared_mutable_state(data) }, cant_nest: () } + RWARCInner { lock: rwlock_with_condvars(num_condvars), + failed: false, data: user_data }; + RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () } } -impl &rw_arc { +impl &RWARC { /// Duplicate a rwlock-protected ARC, as arc::clone. - fn clone() -> rw_arc { - rw_arc { x: unsafe { clone_shared_mutable_state(&self.x) }, - cant_nest: () } + fn clone() -> RWARC { + RWARC { x: unsafe { clone_shared_mutable_state(&self.x) }, + cant_nest: () } } /** @@ -277,7 +278,7 @@ impl &rw_arc { * # Failure * * Failing while inside the ARC will unlock the ARC while unwinding, so - * that other tasks won't block forever. As mutex_arc.access, it will also + * that other tasks won't block forever. As MutexARC.access, it will also * poison the ARC, so subsequent readers and writers will both also fail. */ #[inline(always)] @@ -285,19 +286,19 @@ impl &rw_arc { let state = unsafe { get_shared_mutable_state(&self.x) }; do borrow_rwlock(state).write { check_poison(false, state.failed); - let _z = poison_on_fail(&mut state.failed); + let _z = PoisonOnFail(&mut state.failed); blk(&mut state.data) } } /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline(always)] - fn write_cond(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U { + fn write_cond(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U { let state = unsafe { get_shared_mutable_state(&self.x) }; do borrow_rwlock(state).write_cond |cond| { check_poison(false, state.failed); - let _z = poison_on_fail(&mut state.failed); + let _z = PoisonOnFail(&mut state.failed); blk(&mut state.data, - &condvar { is_mutex: false, failed: &mut state.failed, + &Condvar { is_mutex: false, failed: &mut state.failed, cond: cond }) } } @@ -320,9 +321,9 @@ impl &rw_arc { /** * As write(), but with the ability to atomically 'downgrade' the lock. - * See sync::rwlock.write_downgrade(). The rw_write_mode token must be - * used to obtain the &mut T, and can be transformed into a rw_read_mode - * token by calling downgrade(), after which a &T can be obtained instead. + * See sync::rwlock.write_downgrade(). The RWWriteMode token must be used + * to obtain the &mut T, and can be transformed into a RWReadMode token by + * calling downgrade(), after which a &T can be obtained instead. * ~~~ * do arc.write_downgrade |write_mode| { * do (&write_mode).write_cond |state, condvar| { @@ -335,20 +336,20 @@ impl &rw_arc { * } * ~~~ */ - fn write_downgrade(blk: fn(+rw_write_mode) -> U) -> U { + fn write_downgrade(blk: fn(+RWWriteMode) -> U) -> U { let state = unsafe { get_shared_mutable_state(&self.x) }; do borrow_rwlock(state).write_downgrade |write_mode| { check_poison(false, state.failed); - blk(rw_write_mode((&mut state.data, write_mode, - poison_on_fail(&mut state.failed)))) + blk(RWWriteMode((&mut state.data, write_mode, + PoisonOnFail(&mut state.failed)))) } } /// To be called inside of the write_downgrade block. - fn downgrade(+token: rw_write_mode/&a) -> rw_read_mode/&a { + fn downgrade(+token: RWWriteMode/&a) -> RWReadMode/&a { // The rwlock should assert that the token belongs to us for us. let state = unsafe { get_shared_immutable_state(&self.x) }; - let rw_write_mode((data, t, _poison)) = token; + let RWWriteMode((data, t, _poison)) = token; // Let readers in let new_token = (&state.lock).downgrade(t); // Whatever region the input reference had, it will be safe to use @@ -358,7 +359,7 @@ impl &rw_arc { // Downgrade ensured the token belonged to us. Just a sanity check. assert ptr::ref_eq(&state.data, new_data); // Produce new token - rw_read_mode((new_data, new_token)) + RWReadMode((new_data, new_token)) } } @@ -370,12 +371,12 @@ impl &rw_arc { * in write mode. */ // FIXME(#2585) make this a by-move method on the arc -fn unwrap_rw_arc(+arc: rw_arc) -> T { - let rw_arc { x: x, _ } = arc; +fn unwrap_rw_arc(+arc: RWARC) -> T { + let RWARC { x: x, _ } = arc; let inner = unsafe { unwrap_shared_mutable_state(x) }; - let rw_arc_inner { failed: failed, data: data, _ } = inner; + let RWARCInner { failed: failed, data: data, _ } = inner; if failed { - fail ~"Can't unwrap poisoned rw_arc - another task failed inside!" + fail ~"Can't unwrap poisoned RWARC - another task failed inside!" } data } @@ -384,35 +385,35 @@ fn unwrap_rw_arc(+arc: rw_arc) -> T { // lock it. This wraps the unsafety, with the justification that the 'lock' // field is never overwritten; only 'failed' and 'data'. #[doc(hidden)] -fn borrow_rwlock(state: &r/mut rw_arc_inner) -> &r/RWlock { +fn borrow_rwlock(state: &r/mut RWARCInner) -> &r/RWlock { unsafe { unsafe::transmute_immut(&mut state.lock) } } // FIXME (#3154) ice with struct/& prevents these from being structs. -/// The "write permission" token used for rw_arc.write_downgrade(). -enum rw_write_mode = - (&mut T, sync::RWlockWriteMode, poison_on_fail); -/// The "read permission" token used for rw_arc.write_downgrade(). -enum rw_read_mode = (&T, sync::RWlockReadMode); +/// The "write permission" token used for RWARC.write_downgrade(). +enum RWWriteMode = + (&mut T, sync::RWlockWriteMode, PoisonOnFail); +/// The "read permission" token used for RWARC.write_downgrade(). +enum RWReadMode = (&T, sync::RWlockReadMode); -impl &rw_write_mode { - /// Access the pre-downgrade rw_arc in write mode. +impl &RWWriteMode { + /// Access the pre-downgrade RWARC in write mode. fn write(blk: fn(x: &mut T) -> U) -> U { match *self { - rw_write_mode((data, ref token, _)) => { + RWWriteMode((data, ref token, _)) => { do token.write { blk(data) } } } } - /// Access the pre-downgrade rw_arc in write mode with a condvar. - fn write_cond(blk: fn(x: &x/mut T, c: &c/condvar) -> U) -> U { + /// Access the pre-downgrade RWARC in write mode with a condvar. + fn write_cond(blk: fn(x: &x/mut T, c: &c/Condvar) -> U) -> U { match *self { - rw_write_mode((data, ref token, ref poison)) => { + RWWriteMode((data, ref token, ref poison)) => { do token.write_cond |cond| { - let cvar = condvar { + let cvar = Condvar { is_mutex: false, failed: poison.failed, cond: cond }; blk(data, &cvar) @@ -422,11 +423,11 @@ impl &rw_write_mode { } } -impl &rw_read_mode { +impl &RWReadMode { /// Access the post-downgrade rwlock in read mode. fn read(blk: fn(x: &T) -> U) -> U { match *self { - rw_read_mode((data, ref token)) => { + RWReadMode((data, ref token)) => { do token.read { blk(data) } } } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 03d7e30e898..0dd139250fb 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -52,6 +52,7 @@ mod cell; #[warn(non_camel_case_types)] mod sync; +#[warn(non_camel_case_types)] mod arc; mod comm;