about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorKeegan McAllister <kmcallister@mozilla.com>2015-01-23 11:58:49 -0800
committerKeegan McAllister <kmcallister@mozilla.com>2015-02-06 21:36:07 -0800
commit7324c2cf4f09d44d1bde8c37716de9eca4aac565 (patch)
tree88bada94ec96351665e485f69053f9a3d0ba9b68 /src/libstd
parent96c3a13680d521387007e2f6575483c24561ecb3 (diff)
downloadrust-7324c2cf4f09d44d1bde8c37716de9eca4aac565.tar.gz
rust-7324c2cf4f09d44d1bde8c37716de9eca4aac565.zip
sync: Expose PoisonError::new
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sync/condvar.rs12
-rw-r--r--src/libstd/sync/poison.rs14
2 files changed, 14 insertions, 12 deletions
diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs
index 2ae81ad7dff..d4d722cab3d 100644
--- a/src/libstd/sync/condvar.rs
+++ b/src/libstd/sync/condvar.rs
@@ -16,7 +16,7 @@ use sys::time::SteadyTime;
 use sys_common::condvar as sys;
 use sys_common::mutex as sys_mutex;
 use time::Duration;
-use sync::{mutex, MutexGuard};
+use sync::{mutex, MutexGuard, PoisonError};
 
 /// A Condition Variable
 ///
@@ -228,7 +228,7 @@ impl StaticCondvar {
             mutex::guard_poison(&guard).get()
         };
         if poisoned {
-            Err(poison::new_poison_error(guard))
+            Err(PoisonError::new(guard))
         } else {
             Ok(guard)
         }
@@ -249,7 +249,7 @@ impl StaticCondvar {
             (mutex::guard_poison(&guard).get(), success)
         };
         if poisoned {
-            Err(poison::new_poison_error((guard, success)))
+            Err(PoisonError::new((guard, success)))
         } else {
             Ok((guard, success))
         }
@@ -276,7 +276,7 @@ impl StaticCondvar {
         while !f(guard_result
                     .as_mut()
                     .map(|g| &mut **g)
-                    .map_err(|e| poison::new_poison_error(&mut **e.get_mut()))) {
+                    .map_err(|e| PoisonError::new(&mut **e.get_mut()))) {
             let now = SteadyTime::now();
             let consumed = &now - &start;
             let guard = guard_result.unwrap_or_else(|e| e.into_inner());
@@ -284,7 +284,7 @@ impl StaticCondvar {
                 Ok((new_guard, no_timeout)) => (Ok(new_guard), no_timeout),
                 Err(err) => {
                     let (new_guard, no_timeout) = err.into_inner();
-                    (Err(poison::new_poison_error(new_guard)), no_timeout)
+                    (Err(PoisonError::new(new_guard)), no_timeout)
                 }
             };
             guard_result = new_guard_result;
@@ -292,7 +292,7 @@ impl StaticCondvar {
                 let result = f(guard_result
                                     .as_mut()
                                     .map(|g| &mut **g)
-                                    .map_err(|e| poison::new_poison_error(&mut **e.get_mut())));
+                                    .map_err(|e| PoisonError::new(&mut **e.get_mut())));
                 return poison::map_result(guard_result, |g| (g, result));
             }
         }
diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs
index d9bc37d312e..a93bd31f5ae 100644
--- a/src/libstd/sync/poison.rs
+++ b/src/libstd/sync/poison.rs
@@ -23,7 +23,7 @@ impl Flag {
     pub fn borrow(&self) -> LockResult<Guard> {
         let ret = Guard { panicking: Thread::panicking() };
         if unsafe { *self.failed.get() } {
-            Err(new_poison_error(ret))
+            Err(PoisonError::new(ret))
         } else {
             Ok(ret)
         }
@@ -110,6 +110,12 @@ impl<T> Error for PoisonError<T> {
 }
 
 impl<T> PoisonError<T> {
+    /// Create a `PoisonError`.
+    #[unstable(feature = "std_misc")]
+    pub fn new(guard: T) -> PoisonError<T> {
+        PoisonError { guard: guard }
+    }
+
     /// Consumes this error indicating that a lock is poisoned, returning the
     /// underlying guard to allow access regardless.
     #[unstable(feature = "std_misc")]
@@ -171,15 +177,11 @@ impl<T> Error for TryLockError<T> {
     }
 }
 
-pub fn new_poison_error<T>(guard: T) -> PoisonError<T> {
-    PoisonError { guard: guard }
-}
-
 pub fn map_result<T, U, F>(result: LockResult<T>, f: F)
                            -> LockResult<U>
                            where F: FnOnce(T) -> U {
     match result {
         Ok(t) => Ok(f(t)),
-        Err(PoisonError { guard }) => Err(new_poison_error(f(guard)))
+        Err(PoisonError { guard }) => Err(PoisonError::new(f(guard)))
     }
 }