File tree Expand file tree Collapse file tree 7 files changed +40
-0
lines changed Expand file tree Collapse file tree 7 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ use crate :: sync:: atomic:: Atomic ;
2+ use crate :: time:: Duration ;
3+
4+ /// An atomic for use as a futex that is at least 32-bits but may be larger
5+ pub type Futex = Atomic < Primitive > ;
6+ /// Must be the underlying type of Futex
7+ pub type Primitive = u32 ;
8+
9+ /// An atomic for use as a futex that is at least 8-bits but may be larger.
10+ pub type SmallFutex = Atomic < SmallPrimitive > ;
11+ /// Must be the underlying type of SmallFutex
12+ pub type SmallPrimitive = u32 ;
13+
14+ pub fn futex_wait ( futex : & Atomic < u32 > , expected : u32 , timeout : Option < Duration > ) -> bool {
15+ // FIXME: Infinite timeout is just the max for now
16+ let timeout_duration = timeout. unwrap_or ( Duration :: MAX ) ;
17+ let results = safa_api:: syscalls:: futex:: futex_wait ( futex, expected, timeout_duration)
18+ . expect ( "FATAL System error while waiting for Futex" ) ;
19+ results
20+ }
21+
22+ #[ inline]
23+ pub fn futex_wake ( futex : & Atomic < u32 > ) -> bool {
24+ let results = safa_api:: syscalls:: futex:: futex_wake ( futex, 1 )
25+ . expect ( "FATAL System error while waking 1 Futex" )
26+ > 0 ;
27+ results
28+ }
29+
30+ #[ inline]
31+ pub fn futex_wake_all ( futex : & Atomic < u32 > ) {
32+ safa_api:: syscalls:: futex:: futex_wake ( futex, usize:: MAX )
33+ . expect ( "FATAL System error while waking all Futexes" ) ;
34+ }
Original file line number Diff line number Diff line change 11#![ deny( unsafe_op_in_unsafe_fn) ]
22
3+ pub mod futex;
34pub mod os;
45pub mod pipe;
56pub mod resources;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ cfg_if::cfg_if! {
99 target_os = "fuchsia" ,
1010 all( target_family = "wasm" , target_feature = "atomics" ) ,
1111 target_os = "hermit" ,
12+ target_os = "safaos" ,
1213 ) ) ] {
1314 mod futex;
1415 pub use futex:: Condvar ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ cfg_if::cfg_if! {
88 target_os = "dragonfly" ,
99 all( target_family = "wasm" , target_feature = "atomics" ) ,
1010 target_os = "hermit" ,
11+ target_os = "safaos" ,
1112 ) ) ] {
1213 mod futex;
1314 pub use futex:: Mutex ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ cfg_if::cfg_if! {
1818 target_os = "dragonfly" ,
1919 target_os = "fuchsia" ,
2020 target_os = "hermit" ,
21+ target_os = "safaos" ,
2122 ) ) ] {
2223 mod futex;
2324 pub use futex:: { Once , OnceState } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ cfg_if::cfg_if! {
99 target_os = "fuchsia" ,
1010 all( target_family = "wasm" , target_feature = "atomics" ) ,
1111 target_os = "hermit" ,
12+ target_os = "safaos" ,
1213 ) ) ] {
1314 mod futex;
1415 pub use futex:: RwLock ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ cfg_if::cfg_if! {
99 target_os = "dragonfly" ,
1010 target_os = "fuchsia" ,
1111 target_os = "hermit" ,
12+ target_os = "safaos" ,
1213 ) ) ] {
1314 mod futex;
1415 pub use futex:: Parker ;
You can’t perform that action at this time.
0 commit comments