From a2c2cb942ebb443bfbc864a4606cc2784c850882 Mon Sep 17 00:00:00 2001 From: ville-h Date: Sat, 3 Jan 2015 23:22:09 +0200 Subject: [PATCH 01/11] rename std::sync::RWLock to RwLock --- src/libstd/sync/rwlock.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 431aeb9cae9..af102fc7402 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -59,13 +59,13 @@ use sys_common::rwlock as sys; /// } // write lock is dropped here /// ``` #[stable] -pub struct RWLock { +pub struct RwLock { inner: Box, data: UnsafeCell, } -unsafe impl Send for RWLock {} -unsafe impl Sync for RWLock {} +unsafe impl Send for RwLock {} +unsafe impl Sync for RwLock {} /// Structure representing a statically allocated RWLock. /// @@ -127,11 +127,11 @@ pub struct RWLockWriteGuard<'a, T: 'a> { __marker: marker::NoSend, } -impl RWLock { +impl RwLock { /// Creates a new instance of an RWLock which is unlocked and read to go. #[stable] - pub fn new(t: T) -> RWLock { - RWLock { inner: box RWLOCK_INIT, data: UnsafeCell::new(t) } + pub fn new(t: T) -> RwLock { + RwLock { inner: box RWLOCK_INIT, data: UnsafeCell::new(t) } } /// Locks this rwlock with shared read access, blocking the current thread @@ -228,7 +228,7 @@ impl RWLock { } #[unsafe_destructor] -impl Drop for RWLock { +impl Drop for RwLock { fn drop(&mut self) { unsafe { self.inner.lock.destroy() } } From b2ab5d7658435f8710acc0b0a99ce858af36bd9a Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 01:58:35 +0200 Subject: [PATCH 02/11] fix code and comments referencing RwLock --- src/libstd/sync/mod.rs | 2 +- src/libstd/sync/rwlock.rs | 62 +++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index c09c3b45d3e..3410976a6e4 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -21,7 +21,7 @@ pub use alloc::arc::{Arc, Weak}; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; -pub use self::rwlock::{RWLock, StaticRWLock, RWLOCK_INIT}; +pub use self::rwlock::{RwLock, StaticRWLock, RWLOCK_INIT}; pub use self::rwlock::{RWLockReadGuard, RWLockWriteGuard}; pub use self::condvar::{Condvar, StaticCondvar, CONDVAR_INIT}; pub use self::once::{Once, ONCE_INIT}; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index af102fc7402..087281d6ce6 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -31,17 +31,17 @@ use sys_common::rwlock as sys; /// /// # Poisoning /// -/// RWLocks, like Mutexes, will become poisoned on panics. Note, however, that -/// an RWLock may only be poisoned if a panic occurs while it is locked +/// RwLocks, like Mutexes, will become poisoned on panics. Note, however, that +/// an RwLock may only be poisoned if a panic occurs while it is locked /// exclusively (write mode). If a panic occurs in any reader, then the lock /// will not be poisoned. /// /// # Examples /// /// ``` -/// use std::sync::RWLock; +/// use std::sync::RwLock; /// -/// let lock = RWLock::new(5i); +/// let lock = RwLock::new(5i); /// /// // many reader locks can be held at once /// { @@ -67,11 +67,11 @@ pub struct RwLock { unsafe impl Send for RwLock {} unsafe impl Sync for RwLock {} -/// Structure representing a statically allocated RWLock. +/// Structure representing a statically allocated RwLock. /// /// This structure is intended to be used inside of a `static` and will provide /// automatic global access as well as lazy initialization. The internal -/// resources of this RWLock, however, must be manually deallocated. +/// resources of this RwLock, however, must be manually deallocated. /// /// # Example /// @@ -90,7 +90,7 @@ unsafe impl Sync for RwLock {} /// } /// unsafe { LOCK.destroy() } // free all resources /// ``` -#[unstable = "may be merged with RWLock in the future"] +#[unstable = "may be merged with RwLock in the future"] pub struct StaticRWLock { lock: sys::RWLock, poison: poison::Flag, @@ -100,7 +100,7 @@ unsafe impl Send for StaticRWLock {} unsafe impl Sync for StaticRWLock {} /// Constant initialization for a statically-initialized rwlock. -#[unstable = "may be merged with RWLock in the future"] +#[unstable = "may be merged with RwLock in the future"] pub const RWLOCK_INIT: StaticRWLock = StaticRWLock { lock: sys::RWLOCK_INIT, poison: poison::FLAG_INIT, @@ -128,7 +128,7 @@ pub struct RWLockWriteGuard<'a, T: 'a> { } impl RwLock { - /// Creates a new instance of an RWLock which is unlocked and read to go. + /// Creates a new instance of an RwLock which is unlocked and read to go. #[stable] pub fn new(t: T) -> RwLock { RwLock { inner: box RWLOCK_INIT, data: UnsafeCell::new(t) } @@ -148,7 +148,7 @@ impl RwLock { /// /// # Failure /// - /// This function will return an error if the RWLock is poisoned. An RWLock + /// This function will return an error if the RwLock is poisoned. An RwLock /// is poisoned whenever a writer panics while holding an exclusive lock. /// The failure will occur immediately after the lock has been acquired. #[inline] @@ -169,7 +169,7 @@ impl RwLock { /// /// # Failure /// - /// This function will return an error if the RWLock is poisoned. An RWLock + /// This function will return an error if the RwLock is poisoned. An RwLock /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. @@ -194,7 +194,7 @@ impl RwLock { /// /// # Failure /// - /// This function will return an error if the RWLock is poisoned. An RWLock + /// This function will return an error if the RwLock is poisoned. An RwLock /// is poisoned whenever a writer panics while holding an exclusive lock. /// An error will be returned when the lock is acquired. #[inline] @@ -212,7 +212,7 @@ impl RwLock { /// /// # Failure /// - /// This function will return an error if the RWLock is poisoned. An RWLock + /// This function will return an error if the RwLock is poisoned. An RwLock /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. @@ -242,9 +242,9 @@ impl StaticRWLock { /// Locks this rwlock with shared read access, blocking the current thread /// until it can be acquired. /// - /// See `RWLock::read`. + /// See `RwLock::read`. #[inline] - #[unstable = "may be merged with RWLock in the future"] + #[unstable = "may be merged with RwLock in the future"] pub fn read(&'static self) -> LockResult> { unsafe { self.lock.read() } RWLockReadGuard::new(self, &DUMMY.0) @@ -252,9 +252,9 @@ impl StaticRWLock { /// Attempt to acquire this lock with shared read access. /// - /// See `RWLock::try_read`. + /// See `RwLock::try_read`. #[inline] - #[unstable = "may be merged with RWLock in the future"] + #[unstable = "may be merged with RwLock in the future"] pub fn try_read(&'static self) -> TryLockResult> { if unsafe { self.lock.try_read() } { @@ -267,9 +267,9 @@ impl StaticRWLock { /// Lock this rwlock with exclusive write access, blocking the current /// thread until it can be acquired. /// - /// See `RWLock::write`. + /// See `RwLock::write`. #[inline] - #[unstable = "may be merged with RWLock in the future"] + #[unstable = "may be merged with RwLock in the future"] pub fn write(&'static self) -> LockResult> { unsafe { self.lock.write() } RWLockWriteGuard::new(self, &DUMMY.0) @@ -277,9 +277,9 @@ impl StaticRWLock { /// Attempt to lock this rwlock with exclusive write access. /// - /// See `RWLock::try_write`. + /// See `RwLock::try_write`. #[inline] - #[unstable = "may be merged with RWLock in the future"] + #[unstable = "may be merged with RwLock in the future"] pub fn try_write(&'static self) -> TryLockResult> { if unsafe { self.lock.try_write() } { @@ -295,7 +295,7 @@ impl StaticRWLock { /// active users of the lock, and this also doesn't prevent any future users /// of this lock. This method is required to be called to not leak memory on /// all platforms. - #[unstable = "may be merged with RWLock in the future"] + #[unstable = "may be merged with RwLock in the future"] pub unsafe fn destroy(&'static self) { self.lock.destroy() } @@ -365,11 +365,11 @@ mod tests { use rand::{mod, Rng}; use sync::mpsc::channel; use thread::Thread; - use sync::{Arc, RWLock, StaticRWLock, RWLOCK_INIT}; + use sync::{Arc, RwLock, StaticRWLock, RWLOCK_INIT}; #[test] fn smoke() { - let l = RWLock::new(()); + let l = RwLock::new(()); drop(l.read().unwrap()); drop(l.write().unwrap()); drop((l.read().unwrap(), l.read().unwrap())); @@ -414,7 +414,7 @@ mod tests { #[test] fn test_rw_arc_poison_wr() { - let arc = Arc::new(RWLock::new(1i)); + let arc = Arc::new(RwLock::new(1i)); let arc2 = arc.clone(); let _: Result = Thread::spawn(move|| { let _lock = arc2.write().unwrap(); @@ -425,7 +425,7 @@ mod tests { #[test] fn test_rw_arc_poison_ww() { - let arc = Arc::new(RWLock::new(1i)); + let arc = Arc::new(RwLock::new(1i)); let arc2 = arc.clone(); let _: Result = Thread::spawn(move|| { let _lock = arc2.write().unwrap(); @@ -436,7 +436,7 @@ mod tests { #[test] fn test_rw_arc_no_poison_rr() { - let arc = Arc::new(RWLock::new(1i)); + let arc = Arc::new(RwLock::new(1i)); let arc2 = arc.clone(); let _: Result = Thread::spawn(move|| { let _lock = arc2.read().unwrap(); @@ -447,7 +447,7 @@ mod tests { } #[test] fn test_rw_arc_no_poison_rw() { - let arc = Arc::new(RWLock::new(1i)); + let arc = Arc::new(RwLock::new(1i)); let arc2 = arc.clone(); let _: Result = Thread::spawn(move|| { let _lock = arc2.read().unwrap(); @@ -459,7 +459,7 @@ mod tests { #[test] fn test_rw_arc() { - let arc = Arc::new(RWLock::new(0i)); + let arc = Arc::new(RwLock::new(0i)); let arc2 = arc.clone(); let (tx, rx) = channel(); @@ -497,11 +497,11 @@ mod tests { #[test] fn test_rw_arc_access_in_unwind() { - let arc = Arc::new(RWLock::new(1i)); + let arc = Arc::new(RwLock::new(1i)); let arc2 = arc.clone(); let _ = Thread::spawn(move|| -> () { struct Unwinder { - i: Arc>, + i: Arc>, } impl Drop for Unwinder { fn drop(&mut self) { From fedbde66239d4a7a7551938975d4e3894d778332 Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 02:03:09 +0200 Subject: [PATCH 03/11] rename std::sync::StaticRWLock to StaticRwLock --- src/libstd/sync/rwlock.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 087281d6ce6..5743386e055 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -91,13 +91,13 @@ unsafe impl Sync for RwLock {} /// unsafe { LOCK.destroy() } // free all resources /// ``` #[unstable = "may be merged with RwLock in the future"] -pub struct StaticRWLock { +pub struct StaticRwLock { lock: sys::RWLock, poison: poison::Flag, } -unsafe impl Send for StaticRWLock {} -unsafe impl Sync for StaticRWLock {} +unsafe impl Send for StaticRwLock {} +unsafe impl Sync for StaticRwLock {} /// Constant initialization for a statically-initialized rwlock. #[unstable = "may be merged with RwLock in the future"] @@ -238,7 +238,7 @@ struct Dummy(UnsafeCell<()>); unsafe impl Sync for Dummy {} static DUMMY: Dummy = Dummy(UnsafeCell { value: () }); -impl StaticRWLock { +impl StaticRwLock { /// Locks this rwlock with shared read access, blocking the current thread /// until it can be acquired. /// From 817f75d2fbc15dd152c9473e012ec5271cb5e94b Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 08:59:06 +0200 Subject: [PATCH 04/11] fix code and comments referencing StaticRwLock --- src/libstd/sync/mod.rs | 2 +- src/libstd/sync/rwlock.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 3410976a6e4..0e2b0a441e6 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -21,7 +21,7 @@ pub use alloc::arc::{Arc, Weak}; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; -pub use self::rwlock::{RwLock, StaticRWLock, RWLOCK_INIT}; +pub use self::rwlock::{RwLock, StaticRwLock, RWLOCK_INIT}; pub use self::rwlock::{RWLockReadGuard, RWLockWriteGuard}; pub use self::condvar::{Condvar, StaticCondvar, CONDVAR_INIT}; pub use self::once::{Once, ONCE_INIT}; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 5743386e055..04efbf893ea 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -60,7 +60,7 @@ use sys_common::rwlock as sys; /// ``` #[stable] pub struct RwLock { - inner: Box, + inner: Box, data: UnsafeCell, } @@ -76,9 +76,9 @@ unsafe impl Sync for RwLock {} /// # Example /// /// ``` -/// use std::sync::{StaticRWLock, RWLOCK_INIT}; +/// use std::sync::{StaticRwLock, RWLOCK_INIT}; /// -/// static LOCK: StaticRWLock = RWLOCK_INIT; +/// static LOCK: StaticRwLock = RWLOCK_INIT; /// /// { /// let _g = LOCK.read().unwrap(); @@ -101,7 +101,7 @@ unsafe impl Sync for StaticRwLock {} /// Constant initialization for a statically-initialized rwlock. #[unstable = "may be merged with RwLock in the future"] -pub const RWLOCK_INIT: StaticRWLock = StaticRWLock { +pub const RWLOCK_INIT: StaticRwLock = StaticRwLock { lock: sys::RWLOCK_INIT, poison: poison::FLAG_INIT, }; @@ -111,7 +111,7 @@ pub const RWLOCK_INIT: StaticRWLock = StaticRWLock { #[must_use] #[stable] pub struct RWLockReadGuard<'a, T: 'a> { - __lock: &'a StaticRWLock, + __lock: &'a StaticRwLock, __data: &'a UnsafeCell, __marker: marker::NoSend, } @@ -121,7 +121,7 @@ pub struct RWLockReadGuard<'a, T: 'a> { #[must_use] #[stable] pub struct RWLockWriteGuard<'a, T: 'a> { - __lock: &'a StaticRWLock, + __lock: &'a StaticRwLock, __data: &'a UnsafeCell, __poison: poison::Guard, __marker: marker::NoSend, @@ -302,7 +302,7 @@ impl StaticRwLock { } impl<'rwlock, T> RWLockReadGuard<'rwlock, T> { - fn new(lock: &'rwlock StaticRWLock, data: &'rwlock UnsafeCell) + fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell) -> LockResult> { poison::map_result(lock.poison.borrow(), |_| { RWLockReadGuard { @@ -314,7 +314,7 @@ impl<'rwlock, T> RWLockReadGuard<'rwlock, T> { } } impl<'rwlock, T> RWLockWriteGuard<'rwlock, T> { - fn new(lock: &'rwlock StaticRWLock, data: &'rwlock UnsafeCell) + fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell) -> LockResult> { poison::map_result(lock.poison.borrow(), |guard| { RWLockWriteGuard { @@ -365,7 +365,7 @@ mod tests { use rand::{mod, Rng}; use sync::mpsc::channel; use thread::Thread; - use sync::{Arc, RwLock, StaticRWLock, RWLOCK_INIT}; + use sync::{Arc, RwLock, StaticRwLock, RWLOCK_INIT}; #[test] fn smoke() { @@ -378,7 +378,7 @@ mod tests { #[test] fn static_smoke() { - static R: StaticRWLock = RWLOCK_INIT; + static R: StaticRwLock = RWLOCK_INIT; drop(R.read().unwrap()); drop(R.write().unwrap()); drop((R.read().unwrap(), R.read().unwrap())); @@ -388,7 +388,7 @@ mod tests { #[test] fn frob() { - static R: StaticRWLock = RWLOCK_INIT; + static R: StaticRwLock = RWLOCK_INIT; static N: uint = 10; static M: uint = 1000; From 5344ae2d4f66f5e8392b325320eeec0af29f503c Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 09:03:27 +0200 Subject: [PATCH 05/11] rename std::sync::RWLOCK_INIT to RW_LOCK_INIT --- src/libstd/sync/rwlock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 04efbf893ea..7b673838339 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -101,7 +101,7 @@ unsafe impl Sync for StaticRwLock {} /// Constant initialization for a statically-initialized rwlock. #[unstable = "may be merged with RwLock in the future"] -pub const RWLOCK_INIT: StaticRwLock = StaticRwLock { +pub const RW_LOCK_INIT: StaticRwLock = StaticRwLock { lock: sys::RWLOCK_INIT, poison: poison::FLAG_INIT, }; From c3dcf9b6bf7b3de4b7b4f51725f2ab814cbdfd38 Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 10:57:05 +0200 Subject: [PATCH 06/11] fix code and comments referencing RW_LOCK_INIT --- src/libstd/sync/mod.rs | 2 +- src/libstd/sync/rwlock.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 0e2b0a441e6..3bb0e257577 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -21,7 +21,7 @@ pub use alloc::arc::{Arc, Weak}; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; -pub use self::rwlock::{RwLock, StaticRwLock, RWLOCK_INIT}; +pub use self::rwlock::{RwLock, StaticRwLock, RW_LOCK_INIT}; pub use self::rwlock::{RWLockReadGuard, RWLockWriteGuard}; pub use self::condvar::{Condvar, StaticCondvar, CONDVAR_INIT}; pub use self::once::{Once, ONCE_INIT}; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 7b673838339..f6fffd49dee 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -76,9 +76,9 @@ unsafe impl Sync for RwLock {} /// # Example /// /// ``` -/// use std::sync::{StaticRwLock, RWLOCK_INIT}; +/// use std::sync::{StaticRwLock, RW_LOCK_INIT}; /// -/// static LOCK: StaticRwLock = RWLOCK_INIT; +/// static LOCK: StaticRwLock = RW_LOCK_INIT; /// /// { /// let _g = LOCK.read().unwrap(); @@ -131,7 +131,7 @@ impl RwLock { /// Creates a new instance of an RwLock which is unlocked and read to go. #[stable] pub fn new(t: T) -> RwLock { - RwLock { inner: box RWLOCK_INIT, data: UnsafeCell::new(t) } + RwLock { inner: box RW_LOCK_INIT, data: UnsafeCell::new(t) } } /// Locks this rwlock with shared read access, blocking the current thread @@ -365,7 +365,7 @@ mod tests { use rand::{mod, Rng}; use sync::mpsc::channel; use thread::Thread; - use sync::{Arc, RwLock, StaticRwLock, RWLOCK_INIT}; + use sync::{Arc, RwLock, StaticRwLock, RW_LOCK_INIT}; #[test] fn smoke() { @@ -378,7 +378,7 @@ mod tests { #[test] fn static_smoke() { - static R: StaticRwLock = RWLOCK_INIT; + static R: StaticRwLock = RW_LOCK_INIT; drop(R.read().unwrap()); drop(R.write().unwrap()); drop((R.read().unwrap(), R.read().unwrap())); @@ -388,7 +388,7 @@ mod tests { #[test] fn frob() { - static R: StaticRwLock = RWLOCK_INIT; + static R: StaticRwLock = RW_LOCK_INIT; static N: uint = 10; static M: uint = 1000; From 2dcbdc1edac50af0f1a2796b1dfe2dd082f8190c Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 11:43:14 +0200 Subject: [PATCH 07/11] rename std::sync::RWLockReadGuard to RwLockReadGuard --- src/libstd/sync/rwlock.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index f6fffd49dee..37b9f5dc68d 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -110,7 +110,7 @@ pub const RW_LOCK_INIT: StaticRwLock = StaticRwLock { /// dropped. #[must_use] #[stable] -pub struct RWLockReadGuard<'a, T: 'a> { +pub struct RwLockReadGuard<'a, T: 'a> { __lock: &'a StaticRwLock, __data: &'a UnsafeCell, __marker: marker::NoSend, @@ -301,11 +301,11 @@ impl StaticRwLock { } } -impl<'rwlock, T> RWLockReadGuard<'rwlock, T> { +impl<'rwlock, T> RwLockReadGuard<'rwlock, T> { fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell) - -> LockResult> { + -> LockResult> { poison::map_result(lock.poison.borrow(), |_| { - RWLockReadGuard { + RwLockReadGuard { __lock: lock, __data: data, __marker: marker::NoSend, @@ -327,7 +327,7 @@ impl<'rwlock, T> RWLockWriteGuard<'rwlock, T> { } } -impl<'rwlock, T> Deref for RWLockReadGuard<'rwlock, T> { +impl<'rwlock, T> Deref for RwLockReadGuard<'rwlock, T> { type Target = T; fn deref(&self) -> &T { unsafe { &*self.__data.get() } } @@ -344,7 +344,7 @@ impl<'rwlock, T> DerefMut for RWLockWriteGuard<'rwlock, T> { } #[unsafe_destructor] -impl<'a, T> Drop for RWLockReadGuard<'a, T> { +impl<'a, T> Drop for RwLockReadGuard<'a, T> { fn drop(&mut self) { unsafe { self.__lock.lock.read_unlock(); } } From 956cab6f97c1841e6f3f00acb6386f07eddfc25e Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 11:45:31 +0200 Subject: [PATCH 08/11] fix code referencing RwLockReadGuard --- src/libstd/sync/mod.rs | 2 +- src/libstd/sync/rwlock.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 3bb0e257577..71ff3c7d172 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -22,7 +22,7 @@ pub use alloc::arc::{Arc, Weak}; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; pub use self::rwlock::{RwLock, StaticRwLock, RW_LOCK_INIT}; -pub use self::rwlock::{RWLockReadGuard, RWLockWriteGuard}; +pub use self::rwlock::{RwLockReadGuard, RWLockWriteGuard}; pub use self::condvar::{Condvar, StaticCondvar, CONDVAR_INIT}; pub use self::once::{Once, ONCE_INIT}; pub use self::semaphore::{Semaphore, SemaphoreGuard}; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 37b9f5dc68d..0a8bf6f0aa7 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -153,9 +153,9 @@ impl RwLock { /// The failure will occur immediately after the lock has been acquired. #[inline] #[stable] - pub fn read(&self) -> LockResult> { + pub fn read(&self) -> LockResult> { unsafe { self.inner.lock.read() } - RWLockReadGuard::new(&*self.inner, &self.data) + RwLockReadGuard::new(&*self.inner, &self.data) } /// Attempt to acquire this lock with shared read access. @@ -175,9 +175,9 @@ impl RwLock { /// acquired. #[inline] #[stable] - pub fn try_read(&self) -> TryLockResult> { + pub fn try_read(&self) -> TryLockResult> { if unsafe { self.inner.lock.try_read() } { - Ok(try!(RWLockReadGuard::new(&*self.inner, &self.data))) + Ok(try!(RwLockReadGuard::new(&*self.inner, &self.data))) } else { Err(TryLockError::WouldBlock) } @@ -245,9 +245,9 @@ impl StaticRwLock { /// See `RwLock::read`. #[inline] #[unstable = "may be merged with RwLock in the future"] - pub fn read(&'static self) -> LockResult> { + pub fn read(&'static self) -> LockResult> { unsafe { self.lock.read() } - RWLockReadGuard::new(self, &DUMMY.0) + RwLockReadGuard::new(self, &DUMMY.0) } /// Attempt to acquire this lock with shared read access. @@ -256,9 +256,9 @@ impl StaticRwLock { #[inline] #[unstable = "may be merged with RwLock in the future"] pub fn try_read(&'static self) - -> TryLockResult> { + -> TryLockResult> { if unsafe { self.lock.try_read() } { - Ok(try!(RWLockReadGuard::new(self, &DUMMY.0))) + Ok(try!(RwLockReadGuard::new(self, &DUMMY.0))) } else { Err(TryLockError::WouldBlock) } From 98e6d12017da5e323612108c81accb1f437f7137 Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 12:36:27 +0200 Subject: [PATCH 09/11] rename std::sync::RWLockWriteGuard to RwLockWriteGuard --- src/libstd/sync/rwlock.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 0a8bf6f0aa7..6c2def11ce5 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -120,7 +120,7 @@ pub struct RwLockReadGuard<'a, T: 'a> { /// dropped. #[must_use] #[stable] -pub struct RWLockWriteGuard<'a, T: 'a> { +pub struct RwLockWriteGuard<'a, T: 'a> { __lock: &'a StaticRwLock, __data: &'a UnsafeCell, __poison: poison::Guard, @@ -313,11 +313,11 @@ impl<'rwlock, T> RwLockReadGuard<'rwlock, T> { }) } } -impl<'rwlock, T> RWLockWriteGuard<'rwlock, T> { +impl<'rwlock, T> RwLockWriteGuard<'rwlock, T> { fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell) - -> LockResult> { + -> LockResult> { poison::map_result(lock.poison.borrow(), |guard| { - RWLockWriteGuard { + RwLockWriteGuard { __lock: lock, __data: data, __poison: guard, @@ -332,12 +332,12 @@ impl<'rwlock, T> Deref for RwLockReadGuard<'rwlock, T> { fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } -impl<'rwlock, T> Deref for RWLockWriteGuard<'rwlock, T> { +impl<'rwlock, T> Deref for RwLockWriteGuard<'rwlock, T> { type Target = T; fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } -impl<'rwlock, T> DerefMut for RWLockWriteGuard<'rwlock, T> { +impl<'rwlock, T> DerefMut for RwLockWriteGuard<'rwlock, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__data.get() } } @@ -351,7 +351,7 @@ impl<'a, T> Drop for RwLockReadGuard<'a, T> { } #[unsafe_destructor] -impl<'a, T> Drop for RWLockWriteGuard<'a, T> { +impl<'a, T> Drop for RwLockWriteGuard<'a, T> { fn drop(&mut self) { self.__lock.poison.done(&self.__poison); unsafe { self.__lock.lock.write_unlock(); } From 44b3ddef8df7fa5392ce3608cbe1977f119337ee Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 13:12:17 +0200 Subject: [PATCH 10/11] fix code referencing RwLockWriteGuard --- src/libstd/sync/mod.rs | 2 +- src/libstd/sync/rwlock.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 71ff3c7d172..a2e1eb6c65a 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -22,7 +22,7 @@ pub use alloc::arc::{Arc, Weak}; pub use self::mutex::{Mutex, MutexGuard, StaticMutex}; pub use self::mutex::MUTEX_INIT; pub use self::rwlock::{RwLock, StaticRwLock, RW_LOCK_INIT}; -pub use self::rwlock::{RwLockReadGuard, RWLockWriteGuard}; +pub use self::rwlock::{RwLockReadGuard, RwLockWriteGuard}; pub use self::condvar::{Condvar, StaticCondvar, CONDVAR_INIT}; pub use self::once::{Once, ONCE_INIT}; pub use self::semaphore::{Semaphore, SemaphoreGuard}; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 6c2def11ce5..bc068d0e637 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -199,9 +199,9 @@ impl RwLock { /// An error will be returned when the lock is acquired. #[inline] #[stable] - pub fn write(&self) -> LockResult> { + pub fn write(&self) -> LockResult> { unsafe { self.inner.lock.write() } - RWLockWriteGuard::new(&*self.inner, &self.data) + RwLockWriteGuard::new(&*self.inner, &self.data) } /// Attempt to lock this rwlock with exclusive write access. @@ -218,9 +218,9 @@ impl RwLock { /// acquired. #[inline] #[stable] - pub fn try_write(&self) -> TryLockResult> { + pub fn try_write(&self) -> TryLockResult> { if unsafe { self.inner.lock.try_read() } { - Ok(try!(RWLockWriteGuard::new(&*self.inner, &self.data))) + Ok(try!(RwLockWriteGuard::new(&*self.inner, &self.data))) } else { Err(TryLockError::WouldBlock) } @@ -270,9 +270,9 @@ impl StaticRwLock { /// See `RwLock::write`. #[inline] #[unstable = "may be merged with RwLock in the future"] - pub fn write(&'static self) -> LockResult> { + pub fn write(&'static self) -> LockResult> { unsafe { self.lock.write() } - RWLockWriteGuard::new(self, &DUMMY.0) + RwLockWriteGuard::new(self, &DUMMY.0) } /// Attempt to lock this rwlock with exclusive write access. @@ -281,9 +281,9 @@ impl StaticRwLock { #[inline] #[unstable = "may be merged with RwLock in the future"] pub fn try_write(&'static self) - -> TryLockResult> { + -> TryLockResult> { if unsafe { self.lock.try_write() } { - Ok(try!(RWLockWriteGuard::new(self, &DUMMY.0))) + Ok(try!(RwLockWriteGuard::new(self, &DUMMY.0))) } else { Err(TryLockError::WouldBlock) } From fee1f2ade962c913ba2da81f7a97ab39c6f66989 Mon Sep 17 00:00:00 2001 From: ville-h Date: Sun, 4 Jan 2015 13:26:25 +0200 Subject: [PATCH 11/11] fix comment referencing RwLock --- src/libstd/sync/poison.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index 6e4df118209..385df45b400 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -49,7 +49,7 @@ pub struct Guard { /// A type of error which can be returned whenever a lock is acquired. /// -/// Both Mutexes and RWLocks are poisoned whenever a task fails while the lock +/// Both Mutexes and RwLocks are poisoned whenever a task fails while the lock /// is held. The precise semantics for when a lock is poisoned is documented on /// each lock, but once a lock is poisoned then all future acquisitions will /// return this error.