Skip to content

Commit 3076f4e

Browse files
committedDec 29, 2022
std: pass hint to id-based parking functions
1 parent a9e5c1a commit 3076f4e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed
 

‎library/std/src/sys/sgx/thread_parking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ pub type ThreadId = fortanix_sgx_abi::Tcs;
77

88
pub use super::abi::thread::current;
99

10-
pub fn park() {
10+
pub fn park(_hint: usize) {
1111
usercalls::wait(EV_UNPARK, WAIT_INDEFINITE).unwrap();
1212
}
1313

14-
pub fn park_timeout(dur: Duration) {
14+
pub fn park_timeout(dur: Duration, _hint: usize) {
1515
let timeout = u128::min(dur.as_nanos(), WAIT_INDEFINITE as u128 - 1) as u64;
1616
if let Err(e) = usercalls::wait(EV_UNPARK, timeout) {
1717
assert!(matches!(e.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock))
1818
}
1919
}
2020

21-
pub fn unpark(tid: ThreadId) {
21+
pub fn unpark(tid: ThreadId, _hint: usize) {
2222
let _ = usercalls::send(EV_UNPARK, Some(tid));
2323
}

‎library/std/src/sys/unix/thread_parking/netbsd.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(target_os = "netbsd")]
22

33
use crate::ffi::{c_int, c_void};
4-
use crate::ptr::{null, null_mut};
4+
use crate::ptr;
55
use crate::time::Duration;
66
use libc::{_lwp_self, clockid_t, lwpid_t, time_t, timespec, CLOCK_MONOTONIC};
77

@@ -25,13 +25,13 @@ pub fn current() -> ThreadId {
2525
}
2626

2727
#[inline]
28-
pub fn park() {
28+
pub fn park(hint: usize) {
2929
unsafe {
30-
___lwp_park60(0, 0, null_mut(), 0, null(), null());
30+
___lwp_park60(0, 0, ptr::null_mut(), 0, ptr::invalid(hint), ptr::null());
3131
}
3232
}
3333

34-
pub fn park_timeout(dur: Duration) {
34+
pub fn park_timeout(dur: Duration, hint: usize) {
3535
let mut timeout = timespec {
3636
// Saturate so that the operation will definitely time out
3737
// (even if it is after the heat death of the universe).
@@ -42,13 +42,13 @@ pub fn park_timeout(dur: Duration) {
4242
// Timeout needs to be mutable since it is modified on NetBSD 9.0 and
4343
// above.
4444
unsafe {
45-
___lwp_park60(CLOCK_MONOTONIC, 0, &mut timeout, 0, null(), null());
45+
___lwp_park60(CLOCK_MONOTONIC, 0, &mut timeout, 0, ptr::invalid(hint), ptr::null());
4646
}
4747
}
4848

4949
#[inline]
50-
pub fn unpark(tid: ThreadId) {
50+
pub fn unpark(tid: ThreadId, hint: usize) {
5151
unsafe {
52-
_lwp_unpark(tid, null());
52+
_lwp_unpark(tid, ptr::invalid(hint));
5353
}
5454
}

‎library/std/src/sys_common/thread_parking/id.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Parker {
5656
if state == PARKED {
5757
// Loop to guard against spurious wakeups.
5858
while state == PARKED {
59-
park();
59+
park(self.state.as_mut_ptr().addr());
6060
state = self.state.load(Acquire);
6161
}
6262

@@ -72,7 +72,7 @@ impl Parker {
7272

7373
let state = self.state.fetch_sub(1, Acquire).wrapping_sub(1);
7474
if state == PARKED {
75-
park_timeout(dur);
75+
park_timeout(dur, self.state.as_mut_ptr().addr());
7676
// Swap to ensure that we observe all state changes with acquire
7777
// ordering, even if the state has been changed after the timeout
7878
// occured.
@@ -95,7 +95,7 @@ impl Parker {
9595
// and terminated before this call is made. This call then returns an
9696
// error or wakes up an unrelated thread. The platform API and
9797
// environment does allow this, however.
98-
unpark(tid);
98+
unpark(tid, self.state.as_mut_ptr().addr());
9999
}
100100
}
101101
}

0 commit comments

Comments
 (0)