about summary refs log tree commit diff
path: root/library/std/src/sys/pal/unix/futex.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-18 13:43:57 +0000
committerbors <bors@rust-lang.org>2024-10-18 13:43:57 +0000
commitb0c2d2e5b00339014cba0a31f634af8c146458ed (patch)
tree96daa53ade01532db1875d327410027d507a390b /library/std/src/sys/pal/unix/futex.rs
parent1350eead10c46b9d3c2007fe0ea7892b7d7337ab (diff)
parentcf7ff15a0ddfe0713dd794cd39eb3b3b58ba8d27 (diff)
downloadrust-b0c2d2e5b00339014cba0a31f634af8c146458ed.tar.gz
rust-b0c2d2e5b00339014cba0a31f634af8c146458ed.zip
Auto merge of #131841 - paulmenage:futex-abstraction, r=joboet
Abstract the state type for futexes

In the same way that we expose `SmallAtomic` and `SmallPrimitive` to allow Windows to use a value other than an `AtomicU32` for its futex state, switch the primary futex state type from `AtomicU32` to `futex::Futex`.  The `futex::Futex` type should be usable as an atomic value with underlying primitive type equal to `futex::Primitive`. (`SmallAtomic` is also renamed to `SmallFutex`).

This allows supporting the futex API on systems where the underlying kernel futex implementation requires more user state than simply an `AtomicU32`.

All in-tree futex implementations simply define {`Futex`,`Primitive`} directly as {`AtomicU32`,`u32`}.
Diffstat (limited to 'library/std/src/sys/pal/unix/futex.rs')
-rw-r--r--library/std/src/sys/pal/unix/futex.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/library/std/src/sys/pal/unix/futex.rs b/library/std/src/sys/pal/unix/futex.rs
index cc725045c48..0fc765dc87a 100644
--- a/library/std/src/sys/pal/unix/futex.rs
+++ b/library/std/src/sys/pal/unix/futex.rs
@@ -11,9 +11,14 @@
 use crate::sync::atomic::AtomicU32;
 use crate::time::Duration;
 
+/// An atomic for use as a futex that is at least 32-bits but may be larger
+pub type Futex = AtomicU32;
+/// Must be the underlying type of Futex
+pub type Primitive = u32;
+
 /// An atomic for use as a futex that is at least 8-bits but may be larger.
-pub type SmallAtomic = AtomicU32;
-/// Must be the underlying type of SmallAtomic
+pub type SmallFutex = AtomicU32;
+/// Must be the underlying type of SmallFutex
 pub type SmallPrimitive = u32;
 
 /// Waits for a `futex_wake` operation to wake us.