-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Unify id-based thread parking implementations #105903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9e5c1a
std: unify id-based thread parking implementations
joboet 3076f4e
std: pass hint to id-based parking functions
joboet 9abda03
std: rename `Parker::new` to `Parker::new_in_place`, add safe `Parker…
joboet 898302e
std: remove unnecessary `#[cfg]` on NetBSD
joboet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::abi::usercalls; | ||
use crate::io::ErrorKind; | ||
use crate::time::Duration; | ||
use fortanix_sgx_abi::{EV_UNPARK, WAIT_INDEFINITE}; | ||
|
||
pub type ThreadId = fortanix_sgx_abi::Tcs; | ||
|
||
pub use super::abi::thread::current; | ||
|
||
pub fn park(_hint: usize) { | ||
usercalls::wait(EV_UNPARK, WAIT_INDEFINITE).unwrap(); | ||
} | ||
|
||
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, _hint: usize) { | ||
let _ = usercalls::send(EV_UNPARK, Some(tid)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#![cfg(target_os = "netbsd")] | ||
|
||
joboet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use crate::ffi::{c_int, c_void}; | ||
use crate::ptr; | ||
use crate::time::Duration; | ||
use libc::{_lwp_self, clockid_t, lwpid_t, time_t, timespec, CLOCK_MONOTONIC}; | ||
|
||
extern "C" { | ||
fn ___lwp_park60( | ||
clock_id: clockid_t, | ||
flags: c_int, | ||
ts: *mut timespec, | ||
unpark: lwpid_t, | ||
hint: *const c_void, | ||
unparkhint: *const c_void, | ||
) -> c_int; | ||
fn _lwp_unpark(lwp: lwpid_t, hint: *const c_void) -> c_int; | ||
} | ||
|
||
pub type ThreadId = lwpid_t; | ||
|
||
#[inline] | ||
pub fn current() -> ThreadId { | ||
unsafe { _lwp_self() } | ||
} | ||
|
||
#[inline] | ||
pub fn park(hint: usize) { | ||
unsafe { | ||
___lwp_park60(0, 0, ptr::null_mut(), 0, ptr::invalid(hint), ptr::null()); | ||
} | ||
} | ||
|
||
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). | ||
tv_sec: dur.as_secs().try_into().ok().unwrap_or(time_t::MAX), | ||
tv_nsec: dur.subsec_nanos().into(), | ||
}; | ||
|
||
// Timeout needs to be mutable since it is modified on NetBSD 9.0 and | ||
// above. | ||
unsafe { | ||
___lwp_park60(CLOCK_MONOTONIC, 0, &mut timeout, 0, ptr::invalid(hint), ptr::null()); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn unpark(tid: ThreadId, hint: usize) { | ||
unsafe { | ||
_lwp_unpark(tid, ptr::invalid(hint)); | ||
} | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.