about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2024-04-23 11:49:37 +0200
committerjoboet <jonasboettiger@icloud.com>2024-05-02 12:38:26 +0200
commita56fd370fc3e6b5cfbd9eb0b96f533d0bcca0b1f (patch)
treea1fc69d5c82808c6018e0500d1f77bafdf002b85
parentfcc06c894b17f4d0c80b8934ea5f27faa894c960 (diff)
downloadrust-a56fd370fc3e6b5cfbd9eb0b96f533d0bcca0b1f.tar.gz
rust-a56fd370fc3e6b5cfbd9eb0b96f533d0bcca0b1f.zip
std: move thread parking to `sys::sync`
-rw-r--r--library/std/src/sys/pal/sgx/thread.rs2
-rw-r--r--library/std/src/sys/pal/teeos/mod.rs2
-rw-r--r--library/std/src/sys/pal/uefi/mod.rs2
-rw-r--r--library/std/src/sys/pal/unix/thread_parking.rs (renamed from library/std/src/sys/pal/unix/thread_parking/netbsd.rs)4
-rw-r--r--library/std/src/sys/pal/unix/thread_parking/mod.rs24
-rw-r--r--library/std/src/sys/pal/unsupported/mod.rs1
-rw-r--r--library/std/src/sys/pal/wasi/mod.rs7
-rw-r--r--library/std/src/sys/pal/wasip2/mod.rs9
-rw-r--r--library/std/src/sys/pal/wasm/mod.rs2
-rw-r--r--library/std/src/sys/pal/windows/mod.rs1
-rw-r--r--library/std/src/sys/pal/xous/mod.rs1
-rw-r--r--library/std/src/sys/pal/zkvm/mod.rs3
-rw-r--r--library/std/src/sys/sync/mod.rs2
-rw-r--r--library/std/src/sys/sync/thread_parking/darwin.rs (renamed from library/std/src/sys/pal/unix/thread_parking/darwin.rs)2
-rw-r--r--library/std/src/sys/sync/thread_parking/futex.rs (renamed from library/std/src/sys_common/thread_parking/futex.rs)0
-rw-r--r--library/std/src/sys/sync/thread_parking/id.rs (renamed from library/std/src/sys_common/thread_parking/id.rs)0
-rw-r--r--library/std/src/sys/sync/thread_parking/mod.rs (renamed from library/std/src/sys_common/thread_parking/mod.rs)15
-rw-r--r--library/std/src/sys/sync/thread_parking/pthread.rs (renamed from library/std/src/sys/pal/unix/thread_parking/pthread.rs)2
-rw-r--r--library/std/src/sys/sync/thread_parking/unsupported.rs (renamed from library/std/src/sys/pal/unsupported/thread_parking.rs)0
-rw-r--r--library/std/src/sys/sync/thread_parking/windows.rs (renamed from library/std/src/sys/pal/windows/thread_parking.rs)0
-rw-r--r--library/std/src/sys/sync/thread_parking/xous.rs (renamed from library/std/src/sys/pal/xous/thread_parking.rs)0
-rw-r--r--library/std/src/sys_common/mod.rs1
-rw-r--r--library/std/src/thread/mod.rs2
23 files changed, 25 insertions, 57 deletions
diff --git a/library/std/src/sys/pal/sgx/thread.rs b/library/std/src/sys/pal/sgx/thread.rs
index e2df57b1a1f..7d271e6d2b6 100644
--- a/library/std/src/sys/pal/sgx/thread.rs
+++ b/library/std/src/sys/pal/sgx/thread.rs
@@ -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>);
 
diff --git a/library/std/src/sys/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs
index c392a0ea264..6dd465a12ed 100644
--- a/library/std/src/sys/pal/teeos/mod.rs
+++ b/library/std/src/sys/pal/teeos/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs
index 562b00c2c01..48b74df1384 100644
--- a/library/std/src/sys/pal/uefi/mod.rs
+++ b/library/std/src/sys/pal/uefi/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/unix/thread_parking/netbsd.rs b/library/std/src/sys/pal/unix/thread_parking.rs
index 5eeb37f8763..66ffc006057 100644
--- a/library/std/src/sys/pal/unix/thread_parking/netbsd.rs
+++ b/library/std/src/sys/pal/unix/thread_parking.rs
@@ -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")]
+
 use crate::ffi::{c_int, c_void};
 use crate::ptr;
 use crate::time::Duration;
diff --git a/library/std/src/sys/pal/unix/thread_parking/mod.rs b/library/std/src/sys/pal/unix/thread_parking/mod.rs
deleted file mode 100644
index c7fa39f07b6..00000000000
--- a/library/std/src/sys/pal/unix/thread_parking/mod.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-//! Thread parking on systems without futex support.
-
-#![cfg(not(any(
-    target_os = "linux",
-    target_os = "android",
-    all(target_os = "emscripten", target_feature = "atomics"),
-    target_os = "freebsd",
-    target_os = "openbsd",
-    target_os = "dragonfly",
-    target_os = "fuchsia",
-)))]
-
-cfg_if::cfg_if! {
-    if #[cfg(all(target_vendor = "apple", not(miri)))] {
-        mod darwin;
-        pub use darwin::Parker;
-    } else if #[cfg(target_os = "netbsd")] {
-        mod netbsd;
-        pub use netbsd::{current, park, park_timeout, unpark, ThreadId};
-    } else {
-        mod pthread;
-        pub use pthread::Parker;
-    }
-}
diff --git a/library/std/src/sys/pal/unsupported/mod.rs b/library/std/src/sys/pal/unsupported/mod.rs
index be344fb7cae..01f5cfd4297 100644
--- a/library/std/src/sys/pal/unsupported/mod.rs
+++ b/library/std/src/sys/pal/unsupported/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs
index a78547261ad..c1266619b36 100644
--- a/library/std/src/sys/pal/wasi/mod.rs
+++ b/library/std/src/sys/pal/wasi/mod.rs
@@ -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)]
diff --git a/library/std/src/sys/pal/wasip2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs
index 94aa458d2f9..6787ffb4bed 100644
--- a/library/std/src/sys/pal/wasip2/mod.rs
+++ b/library/std/src/sys/pal/wasip2/mod.rs
@@ -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)]
diff --git a/library/std/src/sys/pal/wasm/mod.rs b/library/std/src/sys/pal/wasm/mod.rs
index 5cbc3e45341..75dd10826cc 100644
--- a/library/std/src/sys/pal/wasm/mod.rs
+++ b/library/std/src/sys/pal/wasm/mod.rs
@@ -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;
     }
 }
 
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index ff41f6e77be..402a205977b 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -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"))] {
diff --git a/library/std/src/sys/pal/xous/mod.rs b/library/std/src/sys/pal/xous/mod.rs
index 7914a255aea..68189bcc2e3 100644
--- a/library/std/src/sys/pal/xous/mod.rs
+++ b/library/std/src/sys/pal/xous/mod.rs
@@ -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"]
diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs
index 4f79f8c4961..0b22eabca6d 100644
--- a/library/std/src/sys/pal/zkvm/mod.rs
+++ b/library/std/src/sys/pal/zkvm/mod.rs
@@ -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;
diff --git a/library/std/src/sys/sync/mod.rs b/library/std/src/sys/sync/mod.rs
index 623e6bccd51..52fac5902a2 100644
--- a/library/std/src/sys/sync/mod.rs
+++ b/library/std/src/sys/sync/mod.rs
@@ -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;
diff --git a/library/std/src/sys/pal/unix/thread_parking/darwin.rs b/library/std/src/sys/sync/thread_parking/darwin.rs
index 8231f3cba2d..973c08f0317 100644
--- a/library/std/src/sys/pal/unix/thread_parking/darwin.rs
+++ b/library/std/src/sys/sync/thread_parking/darwin.rs
@@ -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,
diff --git a/library/std/src/sys_common/thread_parking/futex.rs b/library/std/src/sys/sync/thread_parking/futex.rs
index 588e7b27826..588e7b27826 100644
--- a/library/std/src/sys_common/thread_parking/futex.rs
+++ b/library/std/src/sys/sync/thread_parking/futex.rs
diff --git a/library/std/src/sys_common/thread_parking/id.rs b/library/std/src/sys/sync/thread_parking/id.rs
index 04667439660..04667439660 100644
--- a/library/std/src/sys_common/thread_parking/id.rs
+++ b/library/std/src/sys/sync/thread_parking/id.rs
diff --git a/library/std/src/sys_common/thread_parking/mod.rs b/library/std/src/sys/sync/thread_parking/mod.rs
index c4d3f9ea2f4..ed1a6437faa 100644
--- a/library/std/src/sys_common/thread_parking/mod.rs
+++ b/library/std/src/sys/sync/thread_parking/mod.rs
@@ -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;
     }
 }
diff --git a/library/std/src/sys/pal/unix/thread_parking/pthread.rs b/library/std/src/sys/sync/thread_parking/pthread.rs
index 8e295453d76..fdac1096dbf 100644
--- a/library/std/src/sys/pal/unix/thread_parking/pthread.rs
+++ b/library/std/src/sys/sync/thread_parking/pthread.rs
@@ -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.
diff --git a/library/std/src/sys/pal/unsupported/thread_parking.rs b/library/std/src/sys/sync/thread_parking/unsupported.rs
index 197078bb186..197078bb186 100644
--- a/library/std/src/sys/pal/unsupported/thread_parking.rs
+++ b/library/std/src/sys/sync/thread_parking/unsupported.rs
diff --git a/library/std/src/sys/pal/windows/thread_parking.rs b/library/std/src/sys/sync/thread_parking/windows.rs
index 4b8102d505a..4b8102d505a 100644
--- a/library/std/src/sys/pal/windows/thread_parking.rs
+++ b/library/std/src/sys/sync/thread_parking/windows.rs
diff --git a/library/std/src/sys/pal/xous/thread_parking.rs b/library/std/src/sys/sync/thread_parking/xous.rs
index 0bd0462d77d..0bd0462d77d 100644
--- a/library/std/src/sys/pal/xous/thread_parking.rs
+++ b/library/std/src/sys/sync/thread_parking/xous.rs
diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs
index cc21560fff5..3a38ba1100f 100644
--- a/library/std/src/sys_common/mod.rs
+++ b/library/std/src/sys_common/mod.rs
@@ -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;
 
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 604eb05040b..bc3321f4735 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -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};