about summary refs log tree commit diff
path: root/library/std/src/sys/sync
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-17 03:31:18 +0000
committerbors <bors@rust-lang.org>2024-07-17 03:31:18 +0000
commita28b35eb35ef874d068b8a66e9ff7460fa23a672 (patch)
tree743286dccaf8522f04a2659b7e1029b4eae4d0e4 /library/std/src/sys/sync
parent1a6e777c3c9e5dd57e1e62d95e13eeebaaebac04 (diff)
parent1a1b44fcae5eddac579b4102d96a0ec24b21c569 (diff)
Auto merge of #127840 - tgross35:rollup-jfkg1dq, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - #125206 (Simplify environment variable examples)
 - #126271 (Skip fast path for dec2flt when optimize_for_size)
 - #126776 (Clean up more comments near use declarations)
 - #127444 (`impl Send + Sync` and override `count` for the `CStr::bytes` iterator)
 - #127512 (Terminate `--print link-args` output with newline)
 - #127792 (std: Use `read_unaligned` for reads from DWARF)
 - #127807 (Use futex.rs for Windows thread parking)
 - #127833 (zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`)
 - #127836 (std: Forbid unwrapped unsafe ops in xous and uefi modules)

Failed merges:

 - #127813 (Prevent double reference in generic futex)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/sync')
-rw-r--r--library/std/src/sys/sync/mutex/futex.rs21
-rw-r--r--library/std/src/sys/sync/thread_parking/futex.rs17
-rw-r--r--library/std/src/sys/sync/thread_parking/mod.rs7
-rw-r--r--library/std/src/sys/sync/thread_parking/windows7.rs (renamed from library/std/src/sys/sync/thread_parking/windows.rs)0
4 files changed, 19 insertions, 26 deletions
diff --git a/library/std/src/sys/sync/mutex/futex.rs b/library/std/src/sys/sync/mutex/futex.rs
index 7427cae94d6..81afa94b147 100644
--- a/library/std/src/sys/sync/mutex/futex.rs
+++ b/library/std/src/sys/sync/mutex/futex.rs
@@ -1,19 +1,8 @@
-use crate::sync::atomic::{
-    self,
-    Ordering::{Acquire, Relaxed, Release},
-};
-use crate::sys::futex::{futex_wait, futex_wake};
-
-cfg_if::cfg_if! {
-if #[cfg(windows)] {
-    // On Windows we can have a smol futex
-    type Atomic = atomic::AtomicU8;
-    type State = u8;
-} else {
-    type Atomic = atomic::AtomicU32;
-    type State = u32;
-}
-}
+use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
+use crate::sys::futex::{self, futex_wait, futex_wake};
+
+type Atomic = futex::SmallAtomic;
+type State = futex::SmallPrimitive;
 
 pub struct Mutex {
     futex: Atomic,
diff --git a/library/std/src/sys/sync/thread_parking/futex.rs b/library/std/src/sys/sync/thread_parking/futex.rs
index 588e7b27826..034eececb2a 100644
--- a/library/std/src/sys/sync/thread_parking/futex.rs
+++ b/library/std/src/sys/sync/thread_parking/futex.rs
@@ -1,15 +1,18 @@
+#![forbid(unsafe_op_in_unsafe_fn)]
 use crate::pin::Pin;
-use crate::sync::atomic::AtomicU32;
 use crate::sync::atomic::Ordering::{Acquire, Release};
-use crate::sys::futex::{futex_wait, futex_wake};
+use crate::sys::futex::{self, futex_wait, futex_wake};
 use crate::time::Duration;
 
-const PARKED: u32 = u32::MAX;
-const EMPTY: u32 = 0;
-const NOTIFIED: u32 = 1;
+type Atomic = futex::SmallAtomic;
+type State = futex::SmallPrimitive;
+
+const PARKED: State = State::MAX;
+const EMPTY: State = 0;
+const NOTIFIED: State = 1;
 
 pub struct Parker {
-    state: AtomicU32,
+    state: Atomic,
 }
 
 // Notes about memory ordering:
@@ -36,7 +39,7 @@ impl Parker {
     /// Construct the futex parker. The UNIX parker implementation
     /// requires this to happen in-place.
     pub unsafe fn new_in_place(parker: *mut Parker) {
-        parker.write(Self { state: AtomicU32::new(EMPTY) });
+        unsafe { parker.write(Self { state: Atomic::new(EMPTY) }) };
     }
 
     // Assumes this is only called by the thread that owns the Parker,
diff --git a/library/std/src/sys/sync/thread_parking/mod.rs b/library/std/src/sys/sync/thread_parking/mod.rs
index ed1a6437faa..0ebc5e093ee 100644
--- a/library/std/src/sys/sync/thread_parking/mod.rs
+++ b/library/std/src/sys/sync/thread_parking/mod.rs
@@ -1,5 +1,6 @@
 cfg_if::cfg_if! {
     if #[cfg(any(
+        all(target_os = "windows", not(target_vendor = "win7")),
         target_os = "linux",
         target_os = "android",
         all(target_arch = "wasm32", target_feature = "atomics"),
@@ -18,9 +19,9 @@ 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(target_vendor = "win7")] {
+        mod windows7;
+        pub use windows7::Parker;
     } else if #[cfg(all(target_vendor = "apple", not(miri)))] {
         mod darwin;
         pub use darwin::Parker;
diff --git a/library/std/src/sys/sync/thread_parking/windows.rs b/library/std/src/sys/sync/thread_parking/windows7.rs
index 3a8d40dc5cf..3a8d40dc5cf 100644
--- a/library/std/src/sys/sync/thread_parking/windows.rs
+++ b/library/std/src/sys/sync/thread_parking/windows7.rs