Skip to content

Commit

Permalink
Rollup merge of rust-lang#105695 - joboet:remove_generic_parker, r=m-…
Browse files Browse the repository at this point in the history
…ou-se

Replace generic thread parker with explicit no-op parker

With rust-lang#98391 merged, all platforms supporting threads now have their own parking implementations. Therefore, the generic implementation can be removed. On the remaining platforms (really just WASM without atomics), parking is not supported, so calls to `thread::park` now return instantly, which is [allowed by their API](https://doc.rust-lang.org/nightly/std/thread/fn.park.html). This is a change in behaviour, as spurious wakeups do not currently occur since all platforms guard against them. It is invalid to depend on this, but I'm still going to tag this as libs-api for confirmation.

````@rustbot```` label +T-libs +T-libs-api +A-atomic

r? rust-lang/libs
  • Loading branch information
Manishearth committed May 3, 2023
2 parents 38bbc39 + 9622cde commit 3fa0c08
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 129 deletions.
1 change: 1 addition & 0 deletions library/std/src/sys/unsupported/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod thread;
#[cfg(target_thread_local)]
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod thread_parking;
pub mod time;

mod common;
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sys/unsupported/thread_parking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::pin::Pin;
use crate::time::Duration;

pub struct Parker {}

impl Parker {
pub unsafe fn new_in_place(_parker: *mut Parker) {}
pub unsafe fn park(self: Pin<&Self>) {}
pub unsafe fn park_timeout(self: Pin<&Self>, _dur: Duration) {}
pub fn unpark(self: Pin<&Self>) {}
}
2 changes: 2 additions & 0 deletions library/std/src/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub mod thread;
pub mod thread_local_dtor;
#[path = "../unsupported/thread_local_key.rs"]
pub mod thread_local_key;
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
pub mod time;

cfg_if::cfg_if! {
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ cfg_if::cfg_if! {
pub mod once;
#[path = "../unsupported/thread.rs"]
pub mod thread;
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
}
}

Expand Down
125 changes: 0 additions & 125 deletions library/std/src/sys_common/thread_parking/generic.rs

This file was deleted.

5 changes: 1 addition & 4 deletions library/std/src/sys_common/thread_parking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ cfg_if::cfg_if! {
))] {
mod id;
pub use id::Parker;
} else if #[cfg(any(windows, target_family = "unix"))] {
pub use crate::sys::thread_parking::Parker;
} else {
mod generic;
pub use generic::Parker;
pub use crate::sys::thread_parking::Parker;
}
}

0 comments on commit 3fa0c08

Please sign in to comment.