diff --git a/crossbeam-utils/src/sync/mod.rs b/crossbeam-utils/src/sync/mod.rs index 2483e3ee4..fd400d70e 100644 --- a/crossbeam-utils/src/sync/mod.rs +++ b/crossbeam-utils/src/sync/mod.rs @@ -8,6 +8,6 @@ mod parker; mod sharded_lock; mod wait_group; -pub use self::parker::{Parker, UnparkReason, Unparker}; +pub use self::parker::{Parker, Unparker}; pub use self::sharded_lock::{ShardedLock, ShardedLockReadGuard, ShardedLockWriteGuard}; pub use self::wait_group::WaitGroup; diff --git a/crossbeam-utils/src/sync/parker.rs b/crossbeam-utils/src/sync/parker.rs index 3c78c0a43..bf9d6f347 100644 --- a/crossbeam-utils/src/sync/parker.rs +++ b/crossbeam-utils/src/sync/parker.rs @@ -120,7 +120,7 @@ impl Parker { /// // Waits for the token to become available, but will not wait longer than 500 ms. /// p.park_timeout(Duration::from_millis(500)); /// ``` - pub fn park_timeout(&self, timeout: Duration) -> UnparkReason { + pub fn park_timeout(&self, timeout: Duration) { self.park_deadline(Instant::now() + timeout) } @@ -138,7 +138,7 @@ impl Parker { /// // Waits for the token to become available, but will not wait longer than 500 ms. /// p.park_deadline(deadline); /// ``` - pub fn park_deadline(&self, deadline: Instant) -> UnparkReason { + pub fn park_deadline(&self, deadline: Instant) { self.unparker.inner.park(Some(deadline)) } @@ -301,18 +301,6 @@ impl Clone for Unparker { } } -/// An enum that reports whether a `Parker::park_timeout` or -/// `Parker::park_deadline` returned because another thread called `unpark` or -/// because of a timeout. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum UnparkReason { - /// The park method returned due to a call to `unpark`. - Unparked, - - /// The park method returned due to a timeout. - Timeout, -} - const EMPTY: usize = 0; const PARKED: usize = 1; const NOTIFIED: usize = 2; @@ -324,20 +312,20 @@ struct Inner { } impl Inner { - fn park(&self, deadline: Option) -> UnparkReason { + fn park(&self, deadline: Option) { // If we were previously notified then we consume this notification and return quickly. if self .state .compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst) .is_ok() { - return UnparkReason::Unparked; + return; } // If the timeout is zero, then there is no need to actually block. if let Some(deadline) = deadline { if deadline <= Instant::now() { - return UnparkReason::Timeout; + return; } } @@ -355,7 +343,7 @@ impl Inner { // do that we must read from the write it made to `state`. let old = self.state.swap(EMPTY, SeqCst); assert_eq!(old, NOTIFIED, "park state changed unexpectedly"); - return UnparkReason::Unparked; + return; } Err(n) => panic!("inconsistent park_timeout state: {}", n), } @@ -373,9 +361,8 @@ impl Inner { self.cvar.wait_timeout(m, deadline - now).unwrap().0 } else { // We've timed out; swap out the state back to empty on our way out - return match self.state.swap(EMPTY, SeqCst) { - NOTIFIED => UnparkReason::Unparked, // got a notification - PARKED => UnparkReason::Timeout, // no notification + match self.state.swap(EMPTY, SeqCst) { + NOTIFIED | PARKED => return, n => panic!("inconsistent park_timeout state: {}", n), }; } @@ -388,7 +375,7 @@ impl Inner { .is_ok() { // got a notification - return UnparkReason::Unparked; + return; } // Spurious wakeup, go back to sleep. Alternatively, if we timed out, it will be caught diff --git a/crossbeam-utils/tests/parker.rs b/crossbeam-utils/tests/parker.rs index 6a6d243cd..2bf9c37d4 100644 --- a/crossbeam-utils/tests/parker.rs +++ b/crossbeam-utils/tests/parker.rs @@ -2,7 +2,7 @@ use std::thread::sleep; use std::time::Duration; use std::u32; -use crossbeam_utils::sync::{Parker, UnparkReason}; +use crossbeam_utils::sync::Parker; use crossbeam_utils::thread; #[test] @@ -10,10 +10,7 @@ fn park_timeout_unpark_before() { let p = Parker::new(); for _ in 0..10 { p.unparker().unpark(); - assert_eq!( - p.park_timeout(Duration::from_millis(u32::MAX as u64)), - UnparkReason::Unparked, - ); + p.park_timeout(Duration::from_millis(u32::MAX as u64)); } } @@ -21,10 +18,7 @@ fn park_timeout_unpark_before() { fn park_timeout_unpark_not_called() { let p = Parker::new(); for _ in 0..10 { - assert_eq!( - p.park_timeout(Duration::from_millis(10)), - UnparkReason::Timeout, - ); + p.park_timeout(Duration::from_millis(10)) } } @@ -40,10 +34,7 @@ fn park_timeout_unpark_called_other_thread() { u.unpark(); }); - assert_eq!( - p.park_timeout(Duration::from_millis(u32::MAX as u64)), - UnparkReason::Unparked, - ); + p.park_timeout(Duration::from_millis(u32::MAX as u64)) }) .unwrap(); }