mirror of
https://github.com/rust-lang/rust
synced 2024-10-01 22:34:35 +00:00
std: pass hint to id-based parking functions
This commit is contained in:
parent
a9e5c1a309
commit
3076f4ec30
|
@ -7,17 +7,17 @@
|
|||
|
||||
pub use super::abi::thread::current;
|
||||
|
||||
pub fn park() {
|
||||
pub fn park(_hint: usize) {
|
||||
usercalls::wait(EV_UNPARK, WAIT_INDEFINITE).unwrap();
|
||||
}
|
||||
|
||||
pub fn park_timeout(dur: Duration) {
|
||||
pub fn park_timeout(dur: Duration, _hint: usize) {
|
||||
let timeout = u128::min(dur.as_nanos(), WAIT_INDEFINITE as u128 - 1) as u64;
|
||||
if let Err(e) = usercalls::wait(EV_UNPARK, timeout) {
|
||||
assert!(matches!(e.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpark(tid: ThreadId) {
|
||||
pub fn unpark(tid: ThreadId, _hint: usize) {
|
||||
let _ = usercalls::send(EV_UNPARK, Some(tid));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![cfg(target_os = "netbsd")]
|
||||
|
||||
use crate::ffi::{c_int, c_void};
|
||||
use crate::ptr::{null, null_mut};
|
||||
use crate::ptr;
|
||||
use crate::time::Duration;
|
||||
use libc::{_lwp_self, clockid_t, lwpid_t, time_t, timespec, CLOCK_MONOTONIC};
|
||||
|
||||
|
@ -25,13 +25,13 @@ pub fn current() -> ThreadId {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn park() {
|
||||
pub fn park(hint: usize) {
|
||||
unsafe {
|
||||
___lwp_park60(0, 0, null_mut(), 0, null(), null());
|
||||
___lwp_park60(0, 0, ptr::null_mut(), 0, ptr::invalid(hint), ptr::null());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn park_timeout(dur: Duration) {
|
||||
pub fn park_timeout(dur: Duration, hint: usize) {
|
||||
let mut timeout = timespec {
|
||||
// Saturate so that the operation will definitely time out
|
||||
// (even if it is after the heat death of the universe).
|
||||
|
@ -42,13 +42,13 @@ pub fn park_timeout(dur: Duration) {
|
|||
// Timeout needs to be mutable since it is modified on NetBSD 9.0 and
|
||||
// above.
|
||||
unsafe {
|
||||
___lwp_park60(CLOCK_MONOTONIC, 0, &mut timeout, 0, null(), null());
|
||||
___lwp_park60(CLOCK_MONOTONIC, 0, &mut timeout, 0, ptr::invalid(hint), ptr::null());
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unpark(tid: ThreadId) {
|
||||
pub fn unpark(tid: ThreadId, hint: usize) {
|
||||
unsafe {
|
||||
_lwp_unpark(tid, null());
|
||||
_lwp_unpark(tid, ptr::invalid(hint));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ pub unsafe fn park(self: Pin<&Self>) {
|
|||
if state == PARKED {
|
||||
// Loop to guard against spurious wakeups.
|
||||
while state == PARKED {
|
||||
park();
|
||||
park(self.state.as_mut_ptr().addr());
|
||||
state = self.state.load(Acquire);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ pub unsafe fn park_timeout(self: Pin<&Self>, dur: Duration) {
|
|||
|
||||
let state = self.state.fetch_sub(1, Acquire).wrapping_sub(1);
|
||||
if state == PARKED {
|
||||
park_timeout(dur);
|
||||
park_timeout(dur, self.state.as_mut_ptr().addr());
|
||||
// Swap to ensure that we observe all state changes with acquire
|
||||
// ordering, even if the state has been changed after the timeout
|
||||
// occured.
|
||||
|
@ -95,7 +95,7 @@ pub fn unpark(self: Pin<&Self>) {
|
|||
// and terminated before this call is made. This call then returns an
|
||||
// error or wakes up an unrelated thread. The platform API and
|
||||
// environment does allow this, however.
|
||||
unpark(tid);
|
||||
unpark(tid, self.state.as_mut_ptr().addr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue