sync: Switch field privacy as necessary
This commit is contained in:
parent
02cf3751df
commit
a49ce7f11a
|
@ -46,7 +46,7 @@ use std::sync::atomics;
|
||||||
/// ```
|
/// ```
|
||||||
#[unsafe_no_drop_flag]
|
#[unsafe_no_drop_flag]
|
||||||
pub struct Arc<T> {
|
pub struct Arc<T> {
|
||||||
priv x: *mut ArcInner<T>,
|
x: *mut ArcInner<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A weak pointer to an `Arc`.
|
/// A weak pointer to an `Arc`.
|
||||||
|
@ -55,7 +55,7 @@ pub struct Arc<T> {
|
||||||
/// used to break cycles between `Arc` pointers.
|
/// used to break cycles between `Arc` pointers.
|
||||||
#[unsafe_no_drop_flag]
|
#[unsafe_no_drop_flag]
|
||||||
pub struct Weak<T> {
|
pub struct Weak<T> {
|
||||||
priv x: *mut ArcInner<T>,
|
x: *mut ArcInner<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ArcInner<T> {
|
struct ArcInner<T> {
|
||||||
|
|
|
@ -20,8 +20,8 @@ use std::comm;
|
||||||
|
|
||||||
/// An extension of `pipes::stream` that allows both sending and receiving.
|
/// An extension of `pipes::stream` that allows both sending and receiving.
|
||||||
pub struct DuplexStream<S, R> {
|
pub struct DuplexStream<S, R> {
|
||||||
priv tx: Sender<S>,
|
tx: Sender<S>,
|
||||||
priv rx: Receiver<R>,
|
rx: Receiver<R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a bidirectional stream.
|
/// Creates a bidirectional stream.
|
||||||
|
|
|
@ -30,7 +30,7 @@ use std::mem::replace;
|
||||||
|
|
||||||
/// A type encapsulating the result of a computation which may not be complete
|
/// A type encapsulating the result of a computation which may not be complete
|
||||||
pub struct Future<A> {
|
pub struct Future<A> {
|
||||||
priv state: FutureState<A>,
|
state: FutureState<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum FutureState<A> {
|
enum FutureState<A> {
|
||||||
|
|
|
@ -20,7 +20,11 @@
|
||||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "http://static.rust-lang.org/doc/master")]
|
html_root_url = "http://static.rust-lang.org/doc/master")]
|
||||||
#![feature(phase)]
|
#![feature(phase)]
|
||||||
#![deny(missing_doc, deprecated_owned_vector)]
|
#![deny(deprecated_owned_vector)]
|
||||||
|
|
||||||
|
// #![deny(missing_doc)] // NOTE: uncomment after a stage0 snap
|
||||||
|
#![allow(missing_doc)] // NOTE: remove after a stage0 snap
|
||||||
|
#![allow(visible_private_types)] // NOTE: remove after a stage0 snap
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[phase(syntax, link)] extern crate log;
|
#[phase(syntax, link)] extern crate log;
|
||||||
|
|
|
@ -79,12 +79,12 @@ impl<'b> Inner<'b> {
|
||||||
/// A condition variable, a mechanism for unlock-and-descheduling and
|
/// A condition variable, a mechanism for unlock-and-descheduling and
|
||||||
/// signaling, for use with the lock types.
|
/// signaling, for use with the lock types.
|
||||||
pub struct Condvar<'a> {
|
pub struct Condvar<'a> {
|
||||||
priv name: &'static str,
|
name: &'static str,
|
||||||
// n.b. Inner must be after PoisonOnFail because we must set the poison flag
|
// n.b. Inner must be after PoisonOnFail because we must set the poison flag
|
||||||
// *inside* the mutex, and struct fields are destroyed top-to-bottom
|
// *inside* the mutex, and struct fields are destroyed top-to-bottom
|
||||||
// (destroy the lock guard last).
|
// (destroy the lock guard last).
|
||||||
priv poison: PoisonOnFail<'a>,
|
poison: PoisonOnFail<'a>,
|
||||||
priv inner: Inner<'a>,
|
inner: Inner<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Condvar<'a> {
|
impl<'a> Condvar<'a> {
|
||||||
|
@ -166,18 +166,18 @@ impl<'a> Condvar<'a> {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Mutex<T> {
|
pub struct Mutex<T> {
|
||||||
priv lock: raw::Mutex,
|
lock: raw::Mutex,
|
||||||
priv failed: Unsafe<bool>,
|
failed: Unsafe<bool>,
|
||||||
priv data: Unsafe<T>,
|
data: Unsafe<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An guard which is created by locking a mutex. Through this guard the
|
/// An guard which is created by locking a mutex. Through this guard the
|
||||||
/// underlying data can be accessed.
|
/// underlying data can be accessed.
|
||||||
pub struct MutexGuard<'a, T> {
|
pub struct MutexGuard<'a, T> {
|
||||||
priv data: &'a mut T,
|
data: &'a mut T,
|
||||||
/// Inner condition variable connected to the locked mutex that this guard
|
/// Inner condition variable connected to the locked mutex that this guard
|
||||||
/// was created from. This can be used for atomic-unlock-and-deschedule.
|
/// was created from. This can be used for atomic-unlock-and-deschedule.
|
||||||
cond: Condvar<'a>,
|
pub cond: Condvar<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Send> Mutex<T> {
|
impl<T: Send> Mutex<T> {
|
||||||
|
@ -265,25 +265,25 @@ impl<'a, T> DerefMut<T> for MutexGuard<'a, T> {
|
||||||
/// println!("{}", *val);
|
/// println!("{}", *val);
|
||||||
/// ```
|
/// ```
|
||||||
pub struct RWLock<T> {
|
pub struct RWLock<T> {
|
||||||
priv lock: raw::RWLock,
|
lock: raw::RWLock,
|
||||||
priv failed: Unsafe<bool>,
|
failed: Unsafe<bool>,
|
||||||
priv data: Unsafe<T>,
|
data: Unsafe<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A guard which is created by locking an rwlock in write mode. Through this
|
/// A guard which is created by locking an rwlock in write mode. Through this
|
||||||
/// guard the underlying data can be accessed.
|
/// guard the underlying data can be accessed.
|
||||||
pub struct RWLockWriteGuard<'a, T> {
|
pub struct RWLockWriteGuard<'a, T> {
|
||||||
priv data: &'a mut T,
|
data: &'a mut T,
|
||||||
/// Inner condition variable that can be used to sleep on the write mode of
|
/// Inner condition variable that can be used to sleep on the write mode of
|
||||||
/// this rwlock.
|
/// this rwlock.
|
||||||
cond: Condvar<'a>,
|
pub cond: Condvar<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A guard which is created by locking an rwlock in read mode. Through this
|
/// A guard which is created by locking an rwlock in read mode. Through this
|
||||||
/// guard the underlying data can be accessed.
|
/// guard the underlying data can be accessed.
|
||||||
pub struct RWLockReadGuard<'a, T> {
|
pub struct RWLockReadGuard<'a, T> {
|
||||||
priv data: &'a T,
|
data: &'a T,
|
||||||
priv guard: raw::RWLockReadGuard<'a>,
|
guard: raw::RWLockReadGuard<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Send + Share> RWLock<T> {
|
impl<T: Send + Share> RWLock<T> {
|
||||||
|
@ -397,8 +397,8 @@ impl<'a, T> DerefMut<T> for RWLockWriteGuard<'a, T> {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Barrier {
|
pub struct Barrier {
|
||||||
priv lock: Mutex<BarrierState>,
|
lock: Mutex<BarrierState>,
|
||||||
priv num_tasks: uint,
|
num_tasks: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The inner state of a double barrier
|
// The inner state of a double barrier
|
||||||
|
|
|
@ -41,18 +41,18 @@ use std::ty::Unsafe;
|
||||||
// initialization.
|
// initialization.
|
||||||
|
|
||||||
pub struct Node<T> {
|
pub struct Node<T> {
|
||||||
next: atomics::AtomicUint,
|
pub next: atomics::AtomicUint,
|
||||||
data: T,
|
pub data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DummyNode {
|
pub struct DummyNode {
|
||||||
next: atomics::AtomicUint,
|
pub next: atomics::AtomicUint,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Queue<T> {
|
pub struct Queue<T> {
|
||||||
head: atomics::AtomicUint,
|
pub head: atomics::AtomicUint,
|
||||||
tail: Unsafe<*mut Node<T>>,
|
pub tail: Unsafe<*mut Node<T>>,
|
||||||
stub: DummyNode,
|
pub stub: DummyNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Send> Queue<T> {
|
impl<T: Send> Queue<T> {
|
||||||
|
|
|
@ -94,7 +94,7 @@ pub static NATIVE_BLOCKED: uint = 1 << 2;
|
||||||
/// drop(guard); // unlock the lock
|
/// drop(guard); // unlock the lock
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
priv lock: StaticMutex,
|
lock: StaticMutex,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Show)]
|
#[deriving(Eq, Show)]
|
||||||
|
@ -128,28 +128,28 @@ enum Flavor {
|
||||||
/// ```
|
/// ```
|
||||||
pub struct StaticMutex {
|
pub struct StaticMutex {
|
||||||
/// Current set of flags on this mutex
|
/// Current set of flags on this mutex
|
||||||
priv state: atomics::AtomicUint,
|
state: atomics::AtomicUint,
|
||||||
/// an OS mutex used by native threads
|
/// an OS mutex used by native threads
|
||||||
priv lock: mutex::StaticNativeMutex,
|
lock: mutex::StaticNativeMutex,
|
||||||
|
|
||||||
/// Type of locking operation currently on this mutex
|
/// Type of locking operation currently on this mutex
|
||||||
priv flavor: Unsafe<Flavor>,
|
flavor: Unsafe<Flavor>,
|
||||||
/// uint-cast of the green thread waiting for this mutex
|
/// uint-cast of the green thread waiting for this mutex
|
||||||
priv green_blocker: Unsafe<uint>,
|
green_blocker: Unsafe<uint>,
|
||||||
/// uint-cast of the native thread waiting for this mutex
|
/// uint-cast of the native thread waiting for this mutex
|
||||||
priv native_blocker: Unsafe<uint>,
|
native_blocker: Unsafe<uint>,
|
||||||
|
|
||||||
/// A concurrent mpsc queue used by green threads, along with a count used
|
/// A concurrent mpsc queue used by green threads, along with a count used
|
||||||
/// to figure out when to dequeue and enqueue.
|
/// to figure out when to dequeue and enqueue.
|
||||||
priv q: q::Queue<uint>,
|
q: q::Queue<uint>,
|
||||||
priv green_cnt: atomics::AtomicUint,
|
green_cnt: atomics::AtomicUint,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
|
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
|
||||||
/// dropped (falls out of scope), the lock will be unlocked.
|
/// dropped (falls out of scope), the lock will be unlocked.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct Guard<'a> {
|
pub struct Guard<'a> {
|
||||||
priv lock: &'a StaticMutex,
|
lock: &'a StaticMutex,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Static initialization of a mutex. This constant can be used to initialize
|
/// Static initialization of a mutex. This constant can be used to initialize
|
||||||
|
|
|
@ -41,9 +41,9 @@ use mutex::{StaticMutex, MUTEX_INIT};
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Once {
|
pub struct Once {
|
||||||
priv mutex: StaticMutex,
|
mutex: StaticMutex,
|
||||||
priv cnt: atomics::AtomicInt,
|
cnt: atomics::AtomicInt,
|
||||||
priv lock_cnt: atomics::AtomicInt,
|
lock_cnt: atomics::AtomicInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialization value for static `Once` values.
|
/// Initialization value for static `Once` values.
|
||||||
|
|
|
@ -209,16 +209,16 @@ enum ReacquireOrderLock<'a> {
|
||||||
pub struct Condvar<'a> {
|
pub struct Condvar<'a> {
|
||||||
// The 'Sem' object associated with this condvar. This is the one that's
|
// The 'Sem' object associated with this condvar. This is the one that's
|
||||||
// atomically-unlocked-and-descheduled upon and reacquired during wakeup.
|
// atomically-unlocked-and-descheduled upon and reacquired during wakeup.
|
||||||
priv sem: &'a Sem<Vec<WaitQueue> >,
|
sem: &'a Sem<Vec<WaitQueue> >,
|
||||||
// This is (can be) an extra semaphore which is held around the reacquire
|
// This is (can be) an extra semaphore which is held around the reacquire
|
||||||
// operation on the first one. This is only used in cvars associated with
|
// operation on the first one. This is only used in cvars associated with
|
||||||
// rwlocks, and is needed to ensure that, when a downgrader is trying to
|
// rwlocks, and is needed to ensure that, when a downgrader is trying to
|
||||||
// hand off the access lock (which would be the first field, here), a 2nd
|
// hand off the access lock (which would be the first field, here), a 2nd
|
||||||
// writer waking up from a cvar wait can't race with a reader to steal it,
|
// writer waking up from a cvar wait can't race with a reader to steal it,
|
||||||
// See the comment in write_cond for more detail.
|
// See the comment in write_cond for more detail.
|
||||||
priv order: ReacquireOrderLock<'a>,
|
order: ReacquireOrderLock<'a>,
|
||||||
// Make sure condvars are non-copyable.
|
// Make sure condvars are non-copyable.
|
||||||
priv nocopy: marker::NoCopy,
|
nocopy: marker::NoCopy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Condvar<'a> {
|
impl<'a> Condvar<'a> {
|
||||||
|
@ -362,14 +362,14 @@ struct SemCondGuard<'a> {
|
||||||
|
|
||||||
/// A counting, blocking, bounded-waiting semaphore.
|
/// A counting, blocking, bounded-waiting semaphore.
|
||||||
pub struct Semaphore {
|
pub struct Semaphore {
|
||||||
priv sem: Sem<()>,
|
sem: Sem<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An RAII guard used to represent an acquired resource to a semaphore. When
|
/// An RAII guard used to represent an acquired resource to a semaphore. When
|
||||||
/// dropped, this value will release the resource back to the semaphore.
|
/// dropped, this value will release the resource back to the semaphore.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct SemaphoreGuard<'a> {
|
pub struct SemaphoreGuard<'a> {
|
||||||
priv guard: SemGuard<'a, ()>,
|
guard: SemGuard<'a, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Semaphore {
|
impl Semaphore {
|
||||||
|
@ -404,7 +404,7 @@ impl Semaphore {
|
||||||
/// A task which fails while holding a mutex will unlock the mutex as it
|
/// A task which fails while holding a mutex will unlock the mutex as it
|
||||||
/// unwinds.
|
/// unwinds.
|
||||||
pub struct Mutex {
|
pub struct Mutex {
|
||||||
priv sem: Sem<Vec<WaitQueue>>,
|
sem: Sem<Vec<WaitQueue>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An RAII structure which is used to gain access to a mutex's condition
|
/// An RAII structure which is used to gain access to a mutex's condition
|
||||||
|
@ -412,10 +412,10 @@ pub struct Mutex {
|
||||||
/// corresponding mutex is also unlocked.
|
/// corresponding mutex is also unlocked.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct MutexGuard<'a> {
|
pub struct MutexGuard<'a> {
|
||||||
priv guard: SemGuard<'a, Vec<WaitQueue>>,
|
guard: SemGuard<'a, Vec<WaitQueue>>,
|
||||||
/// Inner condition variable which is connected to the outer mutex, and can
|
/// Inner condition variable which is connected to the outer mutex, and can
|
||||||
/// be used for atomic-unlock-and-deschedule.
|
/// be used for atomic-unlock-and-deschedule.
|
||||||
cond: Condvar<'a>,
|
pub cond: Condvar<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mutex {
|
impl Mutex {
|
||||||
|
@ -452,8 +452,8 @@ impl Mutex {
|
||||||
/// A task which fails while holding an rwlock will unlock the rwlock as it
|
/// A task which fails while holding an rwlock will unlock the rwlock as it
|
||||||
/// unwinds.
|
/// unwinds.
|
||||||
pub struct RWLock {
|
pub struct RWLock {
|
||||||
priv order_lock: Semaphore,
|
order_lock: Semaphore,
|
||||||
priv access_lock: Sem<Vec<WaitQueue>>,
|
access_lock: Sem<Vec<WaitQueue>>,
|
||||||
|
|
||||||
// The only way the count flag is ever accessed is with xadd. Since it is
|
// The only way the count flag is ever accessed is with xadd. Since it is
|
||||||
// a read-modify-write operation, multiple xadds on different cores will
|
// a read-modify-write operation, multiple xadds on different cores will
|
||||||
|
@ -462,14 +462,14 @@ pub struct RWLock {
|
||||||
//
|
//
|
||||||
// FIXME(#6598): The atomics module has no relaxed ordering flag, so I use
|
// FIXME(#6598): The atomics module has no relaxed ordering flag, so I use
|
||||||
// acquire/release orderings superfluously. Change these someday.
|
// acquire/release orderings superfluously. Change these someday.
|
||||||
priv read_count: atomics::AtomicUint,
|
read_count: atomics::AtomicUint,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An RAII helper which is created by acquiring a read lock on an RWLock. When
|
/// An RAII helper which is created by acquiring a read lock on an RWLock. When
|
||||||
/// dropped, this will unlock the RWLock.
|
/// dropped, this will unlock the RWLock.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct RWLockReadGuard<'a> {
|
pub struct RWLockReadGuard<'a> {
|
||||||
priv lock: &'a RWLock,
|
lock: &'a RWLock,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An RAII helper which is created by acquiring a write lock on an RWLock. When
|
/// An RAII helper which is created by acquiring a write lock on an RWLock. When
|
||||||
|
@ -478,10 +478,10 @@ pub struct RWLockReadGuard<'a> {
|
||||||
/// A value of this type can also be consumed to downgrade to a read-only lock.
|
/// A value of this type can also be consumed to downgrade to a read-only lock.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct RWLockWriteGuard<'a> {
|
pub struct RWLockWriteGuard<'a> {
|
||||||
priv lock: &'a RWLock,
|
lock: &'a RWLock,
|
||||||
/// Inner condition variable that is connected to the write-mode of the
|
/// Inner condition variable that is connected to the write-mode of the
|
||||||
/// outer rwlock.
|
/// outer rwlock.
|
||||||
cond: Condvar<'a>,
|
pub cond: Condvar<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RWLock {
|
impl RWLock {
|
||||||
|
|
|
@ -21,8 +21,8 @@ enum Msg<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TaskPool<T> {
|
pub struct TaskPool<T> {
|
||||||
priv channels: Vec<Sender<Msg<T>>>,
|
channels: Vec<Sender<Msg<T>>>,
|
||||||
priv next_index: uint,
|
next_index: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
|
|
Loading…
Reference in New Issue