summary refs log tree commit diff
path: root/src/libstd/sync/mutex.rs
diff options
context:
space:
mode:
authorJonathan Reem <jonathan.reem@gmail.com>2016-01-30 16:39:03 -0800
committerJonathan Reem <jonathan.reem@gmail.com>2016-02-02 16:34:49 -0800
commitfc875b087cdd844fa61204db30c287f3c3179d92 (patch)
tree9b48984185b88a72be5d9c68cb24394da04dd429 /src/libstd/sync/mutex.rs
parentbf60078b48649ef4d3a9cb0034208672b82e9b51 (diff)
downloadrust-fc875b087cdd844fa61204db30c287f3c3179d92.tar.gz
rust-fc875b087cdd844fa61204db30c287f3c3179d92.zip
Add issue number to guard map methods.
Diffstat (limited to 'src/libstd/sync/mutex.rs')
-rw-r--r--src/libstd/sync/mutex.rs46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index ab566f3f945..a6ab5473076 100644
--- a/src/libstd/sync/mutex.rs
+++ b/src/libstd/sync/mutex.rs
@@ -211,8 +211,10 @@ impl<T: ?Sized> Mutex<T> {
     /// this call will return an error once the mutex is acquired.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn lock(&self) -> LockResult<MutexGuard<T>> {
-        unsafe { self.inner.lock.lock() }
-        unsafe { MutexGuard::new(&*self.inner, &self.data) }
+        unsafe {
+            self.inner.lock.lock();
+            MutexGuard::new(&*self.inner, &self.data)
+        }
     }
 
     /// Attempts to acquire this lock.
@@ -230,10 +232,12 @@ impl<T: ?Sized> Mutex<T> {
     /// acquired.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn try_lock(&self) -> TryLockResult<MutexGuard<T>> {
-        if unsafe { self.inner.lock.try_lock() } {
-            Ok(try!(unsafe { MutexGuard::new(&*self.inner, &self.data) }))
-        } else {
-            Err(TryLockError::WouldBlock)
+        unsafe {
+            if self.inner.lock.try_lock() {
+                Ok(try!(MutexGuard::new(&*self.inner, &self.data)))
+            } else {
+                Err(TryLockError::WouldBlock)
+            }
         }
     }
 
@@ -338,17 +342,21 @@ impl StaticMutex {
     /// Acquires this lock, see `Mutex::lock`
     #[inline]
     pub fn lock(&'static self) -> LockResult<MutexGuard<()>> {
-        unsafe { self.lock.lock() }
-        unsafe { MutexGuard::new(self, &DUMMY.0) }
+        unsafe {
+            self.lock.lock();
+            MutexGuard::new(self, &DUMMY.0)
+        }
     }
 
     /// Attempts to grab this lock, see `Mutex::try_lock`
     #[inline]
     pub fn try_lock(&'static self) -> TryLockResult<MutexGuard<()>> {
-        if unsafe { self.lock.try_lock() } {
-            Ok(try!(unsafe { MutexGuard::new(self, &DUMMY.0) }))
-        } else {
-            Err(TryLockError::WouldBlock)
+        unsafe {
+            if self.lock.try_lock() {
+                Ok(try!(MutexGuard::new(self, &DUMMY.0)))
+            } else {
+                Err(TryLockError::WouldBlock)
+            }
         }
     }
 
@@ -393,17 +401,18 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
     /// let x = Mutex::new(vec![1, 2]);
     ///
     /// {
-    ///     let y = MutexGuard::map(x.lock().unwrap(), |v| &mut v[0]);
+    ///     let mut y = MutexGuard::map(x.lock().unwrap(), |v| &mut v[0]);
     ///     *y = 3;
     /// }
     ///
-    /// assert_eq!(&*x.lock(), &[3, 2]);
+    /// assert_eq!(&*x.lock().unwrap(), &[3, 2]);
     /// ```
     #[unstable(feature = "guard_map",
                reason = "recently added, needs RFC for stabilization",
-               issue = "0")]
+               issue = "27746")]
     pub fn map<U: ?Sized, F>(this: Self, cb: F) -> MutexGuard<'mutex, U>
-    where F: FnOnce(&'mutex mut T) -> &'mutex mut U {
+        where F: FnOnce(&'mutex mut T) -> &'mutex mut U
+    {
         // Compute the new data while still owning the original lock
         // in order to correctly poison if the callback panics.
         let data = unsafe { ptr::read(&this.__data) };
@@ -411,8 +420,9 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
 
         // We don't want to unlock the lock by running the destructor of the
         // original lock, so just read the fields we need and forget it.
-        let poison = unsafe { ptr::read(&this.__poison) };
-        let lock = unsafe { ptr::read(&this.__lock) };
+        let (poison, lock) = unsafe {
+            (ptr::read(&this.__poison), ptr::read(&this.__lock))
+        };
         mem::forget(this);
 
         MutexGuard {