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

Move thread parking to sys::sync #124159

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/sgx/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod task_queue {
pub mod wait_notify {
use crate::pin::Pin;
use crate::sync::Arc;
use crate::sys_common::thread_parking::Parker;
use crate::sys::sync::Parker;

pub struct Notifier(Arc<Parker>);

Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub mod thread;
pub mod thread_local_dtor;
#[path = "../unix/thread_local_key.rs"]
pub mod thread_local_key;
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
#[allow(non_upper_case_globals)]
#[path = "../unix/time.rs"]
pub mod time;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub mod stdio;
pub mod thread;
#[path = "../unsupported/thread_local_key.rs"]
pub mod thread_local_key;
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
pub mod time;

mod helpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Only used on NetBSD. If other platforms start using id-based parking, use
// separate modules for each platform.
#![cfg(target_os = "netbsd")]
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm not sure I love this being unix/thread_parking.rs with nothing in the path to indicate it's highly platform specific. If more unix targets do use id-based parking, what should they call their modules? How would that be organised?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'd split them unix/thread_parking/netbsd.rs/unix/thread_parking/*.rs and expose the relevant inferface in unix/thread_parking/mod.rs.


use crate::ffi::{c_int, c_void};
use crate::ptr;
use crate::time::Duration;
Expand Down
24 changes: 0 additions & 24 deletions library/std/src/sys/pal/unix/thread_parking/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/unsupported/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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
7 changes: 0 additions & 7 deletions library/std/src/sys/pal/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod time;

cfg_if::cfg_if! {
if #[cfg(not(target_feature = "atomics"))] {
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
}
}

#[path = "../unsupported/common.rs"]
#[deny(unsafe_op_in_unsafe_fn)]
#[allow(unused)]
Expand Down
9 changes: 0 additions & 9 deletions library/std/src/sys/pal/wasip2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ pub mod thread_local_key;
#[path = "../wasi/time.rs"]
pub mod time;

cfg_if::cfg_if! {
if #[cfg(target_feature = "atomics")] {
compile_error!("The wasm32-wasip2 target does not support atomics");
} else {
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
}
}

#[path = "../unsupported/common.rs"]
#[deny(unsafe_op_in_unsafe_fn)]
#[allow(unused)]
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ cfg_if::cfg_if! {
} else {
#[path = "../unsupported/thread.rs"]
pub mod thread;
#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;
}
}

Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod stdio;
pub mod thread;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod thread_parking;
pub mod time;
cfg_if::cfg_if! {
if #[cfg(not(target_vendor = "uwp"))] {
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/xous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod process;
pub mod stdio;
pub mod thread;
pub mod thread_local_key;
pub mod thread_parking;
pub mod time;

#[path = "../unsupported/common.rs"]
Expand Down
3 changes: 0 additions & 3 deletions library/std/src/sys/pal/zkvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub mod time;
#[path = "../unsupported/thread.rs"]
pub mod thread;

#[path = "../unsupported/thread_parking.rs"]
pub mod thread_parking;

mod abi;

use crate::io as std_io;
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ mod condvar;
mod mutex;
mod once;
mod rwlock;
mod thread_parking;

pub use condvar::Condvar;
pub use mutex::Mutex;
pub use once::{Once, OnceState};
pub use rwlock::RwLock;
pub use thread_parking::Parker;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//! provided by libdispatch, as the underlying Mach semaphore is only dubiously
//! public.

#![allow(non_camel_case_types)]

use crate::pin::Pin;
use crate::sync::atomic::{
AtomicI8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ cfg_if::cfg_if! {
))] {
mod id;
pub use id::Parker;
} else if #[cfg(target_os = "windows")] {
mod windows;
pub use windows::Parker;
} else if #[cfg(all(target_vendor = "apple", not(miri)))] {
mod darwin;
pub use darwin::Parker;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use xous::Parker;
} else if #[cfg(target_family = "unix")] {
mod pthread;
pub use pthread::Parker;
} else {
pub use crate::sys::thread_parking::Parker;
mod unsupported;
pub use unsupported::Parker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Parker {
// This implementation doesn't require `unsafe`, but other implementations
// may assume this is only called by the thread that owns the Parker.
//
// For memory ordering, see std/src/sys_common/thread_parking/futex.rs
// For memory ordering, see futex.rs
pub unsafe fn park(self: Pin<&Self>) {
// If we were previously notified then we consume this notification and
// return quickly.
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod io;
pub mod lazy_box;
pub mod process;
pub mod thread_local_dtor;
pub mod thread_parking;
pub mod wstr;
pub mod wtf8;

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ use crate::ptr::addr_of_mut;
use crate::str;
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sync::Arc;
use crate::sys::sync::Parker;
use crate::sys::thread as imp;
use crate::sys_common::thread_parking::Parker;
use crate::sys_common::{AsInner, IntoInner};
use crate::time::{Duration, Instant};

Expand Down
Loading