88// Licensed under the MIT license.
99// SPDX-License-Identifier: MIT
1010
11- //! Linux-specific `FutexLike` implementation using direct futex syscalls without
12- //! libc.
11+ //! Linux-specific `FutexLike` implementation using direct futex syscalls
12+ //! without libc.
1313//!
1414//! This implementation provides wait/notify synchronization using Linux futex
1515//! system calls directly, supporting no_std/no_alloc environments.
@@ -51,10 +51,7 @@ struct TimeSpec {
5151impl TimeSpec {
5252 /// Create a new TimeSpec from Duration
5353 fn from_duration ( duration : Duration ) -> Self {
54- Self {
55- tv_sec : duration. as_secs ( ) as i64 ,
56- tv_nsec : duration. subsec_nanos ( ) as i64 ,
57- }
54+ Self { tv_sec : duration. as_secs ( ) as i64 , tv_nsec : duration. subsec_nanos ( ) as i64 }
5855 }
5956
6057 /// Create a zero timeout (immediate)
@@ -75,17 +72,15 @@ pub struct LinuxFutex {
7572 _padding : [ u8 ; 60 ] , // 64 - sizeof(AtomicU32)
7673}
7774
78- // Safety: LinuxFutex only contains AtomicU32 and padding, which are safe to send/sync
75+ // Safety: LinuxFutex only contains AtomicU32 and padding, which are safe to
76+ // send/sync
7977unsafe impl Send for LinuxFutex { }
8078unsafe impl Sync for LinuxFutex { }
8179
8280impl LinuxFutex {
8381 /// Creates a new `LinuxFutex` with the given initial value.
8482 pub fn new ( initial_value : u32 ) -> Self {
85- Self {
86- value : AtomicU32 :: new ( initial_value) ,
87- _padding : [ 0 ; 60 ] ,
88- }
83+ Self { value : AtomicU32 :: new ( initial_value) , _padding : [ 0 ; 60 ] }
8984 }
9085
9186 /// Direct syscall implementation of futex
@@ -135,14 +130,7 @@ impl LinuxFutex {
135130 // Call futex wake
136131 // SAFETY: We're calling futex wake with valid parameters.
137132 let result = unsafe {
138- Self :: futex (
139- addr,
140- FUTEX_WAKE_PRIVATE ,
141- count,
142- core:: ptr:: null ( ) ,
143- core:: ptr:: null ( ) ,
144- 0 ,
145- )
133+ Self :: futex ( addr, FUTEX_WAKE_PRIVATE , count, core:: ptr:: null ( ) , core:: ptr:: null ( ) , 0 )
146134 } ;
147135
148136 if result >= 0 {
@@ -203,25 +191,14 @@ impl FutexLike for LinuxFutex {
203191 // SAFETY: We're calling futex with valid parameters. addr points to self.value,
204192 // which is valid for the lifetime of self.
205193 let result = unsafe {
206- Self :: futex (
207- addr,
208- FUTEX_WAIT_PRIVATE ,
209- expected,
210- timeout_ptr,
211- core:: ptr:: null ( ) ,
212- 0 ,
213- )
194+ Self :: futex ( addr, FUTEX_WAIT_PRIVATE , expected, timeout_ptr, core:: ptr:: null ( ) , 0 )
214195 } ;
215196
216197 match result {
217198 0 => Ok ( ( ) ) , // Woken up by notify
218199 -110 => {
219200 // ETIMEDOUT - convert to system error as per trait contract
220- Err ( Error :: new (
221- ErrorCategory :: System ,
222- codes:: SYSTEM_ERROR ,
223- "Futex wait timed out" ,
224- ) )
201+ Err ( Error :: new ( ErrorCategory :: System , codes:: SYSTEM_ERROR , "Futex wait timed out" ) )
225202 }
226203 -11 => {
227204 // EAGAIN - value changed before we could wait, this is success
@@ -247,10 +224,6 @@ impl FutexLike for LinuxFutex {
247224
248225impl fmt:: Display for LinuxFutex {
249226 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
250- write ! (
251- f,
252- "LinuxFutex({})" ,
253- self . value. load( core:: sync:: atomic:: Ordering :: Relaxed )
254- )
227+ write ! ( f, "LinuxFutex({})" , self . value. load( core:: sync:: atomic:: Ordering :: Relaxed ) )
255228 }
256- }
229+ }
0 commit comments