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