Skip to content
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

Rollup of 9 pull requests #98544

Closed
wants to merge 29 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd76552
std: use an event flag based thread parker on SOLID
joboet May 18, 2022
3b6ae15
std: fix deadlock in `Parker`
joboet May 19, 2022
b9660de
std: solve priority issue for Parker
joboet Jun 4, 2022
5823d7b
Partial stabilization of "nonzero_unchecked_ops".
iago-lito May 30, 2022
69e8e7e
Stabilize NonZero* checked operations constness.
iago-lito Jun 9, 2022
caff723
std: relax memory orderings in `Parker`
joboet Jun 7, 2022
0bc536e
Add GDB/LLDB pretty-printers for NonZero types
artemmukhin Jun 20, 2022
cc4f804
Move help popup into a pocket menu as well
GuillaumeGomez Jun 20, 2022
3eb9e1a
Add/update GUI tests for help pocket menu
GuillaumeGomez Jun 20, 2022
e4b2b41
Merge all popover hide functions into one
GuillaumeGomez Jun 22, 2022
99bc979
macros: use typed identifiers in diag derive
davidtwco Jun 23, 2022
abd3467
macros: use typed identifiers in subdiag derive
davidtwco Jun 23, 2022
dc90d1d
errors: remove diagnostic message ctors
davidtwco Jun 23, 2022
7475867
[rustc_parse] Forbid lets in certain places
c410-f3r Jun 25, 2022
dc2cc10
make const_err show up in future breakage reports
RalfJung Jun 4, 2022
af58692
bless remaining tests
RalfJung Jun 4, 2022
3899914
bless after rebase
RalfJung Jun 25, 2022
2339bb2
Update `since` to 1.64 (since we're after 1.63)
scottmcm Jun 26, 2022
0398aa8
Add regression test for #92859
GuillaumeGomez Jun 26, 2022
756118e
Update `std::alloc::System` docs
Veykril Jun 26, 2022
f64ac8e
Rollup merge of #97140 - joboet:solid_parker, r=m-ou-se
matthiaskrgr Jun 26, 2022
65a3144
Rollup merge of #97295 - c410-f3r:yet-another-let-chain, r=compiler-e…
matthiaskrgr Jun 26, 2022
2c42341
Rollup merge of #97743 - RalfJung:const-err-future-breakage, r=estebank
matthiaskrgr Jun 26, 2022
96e9d84
Rollup merge of #97908 - iago-lito:stabilize_nonzero_checked_ops_cons…
matthiaskrgr Jun 26, 2022
436bb62
Rollup merge of #98297 - GuillaumeGomez:help-pocket-menu, r=notriddle
matthiaskrgr Jun 26, 2022
e629404
Rollup merge of #98301 - ortem:pretty-printers-nonzero, r=Mark-Simula…
matthiaskrgr Jun 26, 2022
6960ad9
Rollup merge of #98428 - davidtwco:translation-derive-typed-identifie…
matthiaskrgr Jun 26, 2022
300ad26
Rollup merge of #98535 - GuillaumeGomez:regression-test-92859, r=lcnr
matthiaskrgr Jun 26, 2022
7b82e2e
Rollup merge of #98541 - Veykril:patch-2, r=Dylan-DPC
matthiaskrgr Jun 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
std: solve priority issue for Parker
  • Loading branch information
joboet committed Jun 5, 2022
commit b9660de664cc491b3f22a5c1dadee5a03e506b2a
55 changes: 31 additions & 24 deletions library/std/src/sys_common/thread_parker/wait_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
//! "wait flag").
//!
//! `unpark` changes the state to `NOTIFIED`. If the state was `PARKED`, the thread
//! is or will be sleeping on the wait flag, so we raise it. Only the first thread
//! to call `unpark` will raise the wait flag, so spurious wakeups are avoided
//! (this is especially important for semaphores).
//! is or will be sleeping on the wait flag, so we raise it.

use crate::pin::Pin;
use crate::sync::atomic::AtomicI8;
use crate::sync::atomic::Ordering::SeqCst;
use crate::sync::atomic::Ordering::{Relaxed, SeqCst};
use crate::sys::wait_flag::WaitFlag;
use crate::time::Duration;

Expand All @@ -49,39 +47,48 @@ impl Parker {

// This implementation doesn't require `unsafe` and `Pin`, but other implementations do.
pub unsafe fn park(self: Pin<&Self>) {
// The state values are chosen so that this subtraction changes
// `NOTIFIED` to `EMPTY` and `EMPTY` to `PARKED`.
let state = self.state.fetch_sub(1, SeqCst);
match state {
EMPTY => (),
match self.state.fetch_sub(1, SeqCst) {
// NOTIFIED => EMPTY
NOTIFIED => return,
// EMPTY => PARKED
EMPTY => (),
_ => panic!("inconsistent park state"),
}

self.wait_flag.wait();
// Avoid waking up from spurious wakeups (these are quite likely, see below).
loop {
self.wait_flag.wait();

// We need to do a load here to use `Acquire` ordering.
self.state.swap(EMPTY, SeqCst);
match self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, Relaxed) {
Ok(_) => return,
Err(PARKED) => (),
Err(_) => panic!("inconsistent park state"),
}
}
}

// This implementation doesn't require `unsafe` and `Pin`, but other implementations do.
pub unsafe fn park_timeout(self: Pin<&Self>, dur: Duration) {
let state = self.state.fetch_sub(1, SeqCst);
match state {
EMPTY => (),
match self.state.fetch_sub(1, SeqCst) {
NOTIFIED => return,
EMPTY => (),
_ => panic!("inconsistent park state"),
}

let wakeup = self.wait_flag.wait_timeout(dur);
let state = self.state.swap(EMPTY, SeqCst);
if state == NOTIFIED && !wakeup {
// The token was made available after the wait timed out, but before
// we reset the state, so we need to reset the wait flag to avoid
// spurious wakeups. This wait has no timeout, but we know it will
// return quickly, as the unparking thread will definitely raise the
// flag if it has not already done so.
self.wait_flag.wait();
self.wait_flag.wait_timeout(dur);

// Either a wakeup or a timeout occurred. Wakeups may be spurious, as there can be
// a race condition when `unpark` is performed between receiving the timeout and
// resetting the state, resulting in the eventflag being set unnecessarily. `park`
// is protected against this by looping until the token is actually given, but
// here we cannot easily tell.

// Use `swap` to provide acquire ordering (not strictly necessary, but all other
// implementations do).
match self.state.swap(EMPTY, SeqCst) {
NOTIFIED => (),
PARKED => (),
_ => panic!("inconsistent park state"),
}
}

Expand Down