-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #101611 - GuillaumeGomez:rollup-yw3qtug, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #101475 (Use futex-based locks and thread parker on Hermit) - #101492 (Suggest adding array lengths to references to arrays if possible) - #101495 (Compile spin_loop_hint as pause on x86 even without sse2 enabled) - #101529 (Fix the example code and doctest for Formatter::sign_plus) - #101600 (rustdoc: simplify the codeblock tooltip) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
21 changed files
with
244 additions
and
580 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,39 @@ | ||
use super::abi; | ||
use crate::ptr::null; | ||
use crate::sync::atomic::AtomicU32; | ||
use crate::time::Duration; | ||
|
||
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { | ||
// Calculate the timeout as a relative timespec. | ||
// | ||
// Overflows are rounded up to an infinite timeout (None). | ||
let timespec = timeout.and_then(|dur| { | ||
Some(abi::timespec { | ||
tv_sec: dur.as_secs().try_into().ok()?, | ||
tv_nsec: dur.subsec_nanos().into(), | ||
}) | ||
}); | ||
|
||
let r = unsafe { | ||
abi::futex_wait( | ||
futex.as_mut_ptr(), | ||
expected, | ||
timespec.as_ref().map_or(null(), |t| t as *const abi::timespec), | ||
abi::FUTEX_RELATIVE_TIMEOUT, | ||
) | ||
}; | ||
|
||
r != -abi::errno::ETIMEDOUT | ||
} | ||
|
||
#[inline] | ||
pub fn futex_wake(futex: &AtomicU32) -> bool { | ||
unsafe { abi::futex_wake(futex.as_mut_ptr(), 1) > 0 } | ||
} | ||
|
||
#[inline] | ||
pub fn futex_wake_all(futex: &AtomicU32) { | ||
unsafe { | ||
abi::futex_wake(futex.as_mut_ptr(), i32::MAX); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.