Skip to content

Commit 927c3f8

Browse files
committed
Remove UnparkReason to preserve compatibility.
`UnparkReason` implementation preserved in Lucretiel/crossbeam/unpark-reason
1 parent 38cd5b3 commit 927c3f8

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

crossbeam-utils/src/sync/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ mod parker;
88
mod sharded_lock;
99
mod wait_group;
1010

11-
pub use self::parker::{Parker, UnparkReason, Unparker};
11+
pub use self::parker::{Parker, Unparker};
1212
pub use self::sharded_lock::{ShardedLock, ShardedLockReadGuard, ShardedLockWriteGuard};
1313
pub use self::wait_group::WaitGroup;

crossbeam-utils/src/sync/parker.rs

+9-22
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Parker {
120120
/// // Waits for the token to become available, but will not wait longer than 500 ms.
121121
/// p.park_timeout(Duration::from_millis(500));
122122
/// ```
123-
pub fn park_timeout(&self, timeout: Duration) -> UnparkReason {
123+
pub fn park_timeout(&self, timeout: Duration) {
124124
self.park_deadline(Instant::now() + timeout)
125125
}
126126

@@ -138,7 +138,7 @@ impl Parker {
138138
/// // Waits for the token to become available, but will not wait longer than 500 ms.
139139
/// p.park_deadline(deadline);
140140
/// ```
141-
pub fn park_deadline(&self, deadline: Instant) -> UnparkReason {
141+
pub fn park_deadline(&self, deadline: Instant) {
142142
self.unparker.inner.park(Some(deadline))
143143
}
144144

@@ -301,18 +301,6 @@ impl Clone for Unparker {
301301
}
302302
}
303303

304-
/// An enum that reports whether a `Parker::park_timeout` or
305-
/// `Parker::park_deadline` returned because another thread called `unpark` or
306-
/// because of a timeout.
307-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
308-
pub enum UnparkReason {
309-
/// The park method returned due to a call to `unpark`.
310-
Unparked,
311-
312-
/// The park method returned due to a timeout.
313-
Timeout,
314-
}
315-
316304
const EMPTY: usize = 0;
317305
const PARKED: usize = 1;
318306
const NOTIFIED: usize = 2;
@@ -324,20 +312,20 @@ struct Inner {
324312
}
325313

326314
impl Inner {
327-
fn park(&self, deadline: Option<Instant>) -> UnparkReason {
315+
fn park(&self, deadline: Option<Instant>) {
328316
// If we were previously notified then we consume this notification and return quickly.
329317
if self
330318
.state
331319
.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst)
332320
.is_ok()
333321
{
334-
return UnparkReason::Unparked;
322+
return;
335323
}
336324

337325
// If the timeout is zero, then there is no need to actually block.
338326
if let Some(deadline) = deadline {
339327
if deadline <= Instant::now() {
340-
return UnparkReason::Timeout;
328+
return;
341329
}
342330
}
343331

@@ -355,7 +343,7 @@ impl Inner {
355343
// do that we must read from the write it made to `state`.
356344
let old = self.state.swap(EMPTY, SeqCst);
357345
assert_eq!(old, NOTIFIED, "park state changed unexpectedly");
358-
return UnparkReason::Unparked;
346+
return;
359347
}
360348
Err(n) => panic!("inconsistent park_timeout state: {}", n),
361349
}
@@ -373,9 +361,8 @@ impl Inner {
373361
self.cvar.wait_timeout(m, deadline - now).unwrap().0
374362
} else {
375363
// We've timed out; swap out the state back to empty on our way out
376-
return match self.state.swap(EMPTY, SeqCst) {
377-
NOTIFIED => UnparkReason::Unparked, // got a notification
378-
PARKED => UnparkReason::Timeout, // no notification
364+
match self.state.swap(EMPTY, SeqCst) {
365+
NOTIFIED | PARKED => return,
379366
n => panic!("inconsistent park_timeout state: {}", n),
380367
};
381368
}
@@ -388,7 +375,7 @@ impl Inner {
388375
.is_ok()
389376
{
390377
// got a notification
391-
return UnparkReason::Unparked;
378+
return;
392379
}
393380

394381
// Spurious wakeup, go back to sleep. Alternatively, if we timed out, it will be caught

crossbeam-utils/tests/parker.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@ use std::thread::sleep;
22
use std::time::Duration;
33
use std::u32;
44

5-
use crossbeam_utils::sync::{Parker, UnparkReason};
5+
use crossbeam_utils::sync::Parker;
66
use crossbeam_utils::thread;
77

88
#[test]
99
fn park_timeout_unpark_before() {
1010
let p = Parker::new();
1111
for _ in 0..10 {
1212
p.unparker().unpark();
13-
assert_eq!(
14-
p.park_timeout(Duration::from_millis(u32::MAX as u64)),
15-
UnparkReason::Unparked,
16-
);
13+
p.park_timeout(Duration::from_millis(u32::MAX as u64));
1714
}
1815
}
1916

2017
#[test]
2118
fn park_timeout_unpark_not_called() {
2219
let p = Parker::new();
2320
for _ in 0..10 {
24-
assert_eq!(
25-
p.park_timeout(Duration::from_millis(10)),
26-
UnparkReason::Timeout,
27-
);
21+
p.park_timeout(Duration::from_millis(10))
2822
}
2923
}
3024

@@ -40,10 +34,7 @@ fn park_timeout_unpark_called_other_thread() {
4034
u.unpark();
4135
});
4236

43-
assert_eq!(
44-
p.park_timeout(Duration::from_millis(u32::MAX as u64)),
45-
UnparkReason::Unparked,
46-
);
37+
p.park_timeout(Duration::from_millis(u32::MAX as u64))
4738
})
4839
.unwrap();
4940
}

0 commit comments

Comments
 (0)