File tree Expand file tree Collapse file tree 4 files changed +42
-36
lines changed Expand file tree Collapse file tree 4 files changed +42
-36
lines changed Original file line number Diff line number Diff line change 1+ #![ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
2+
3+ use crate :: sync:: atomic:: AtomicI32 ;
4+ use crate :: time:: Duration ;
5+
6+ pub fn futex_wait ( futex : & AtomicI32 , expected : i32 , timeout : Option < Duration > ) {
7+ let timespec;
8+ let timespec_ptr = match timeout {
9+ Some ( timeout) => {
10+ timespec = libc:: timespec {
11+ tv_sec : timeout. as_secs ( ) as _ ,
12+ tv_nsec : timeout. subsec_nanos ( ) as _ ,
13+ } ;
14+ & timespec as * const libc:: timespec
15+ }
16+ None => crate :: ptr:: null ( ) ,
17+ } ;
18+ unsafe {
19+ libc:: syscall (
20+ libc:: SYS_futex ,
21+ futex as * const AtomicI32 ,
22+ libc:: FUTEX_WAIT | libc:: FUTEX_PRIVATE_FLAG ,
23+ expected,
24+ timespec_ptr,
25+ ) ;
26+ }
27+ }
28+
29+ pub fn futex_wake ( futex : & AtomicI32 ) {
30+ unsafe {
31+ libc:: syscall (
32+ libc:: SYS_futex ,
33+ futex as * const AtomicI32 ,
34+ libc:: FUTEX_WAKE | libc:: FUTEX_PRIVATE_FLAG ,
35+ 1 ,
36+ ) ;
37+ }
38+ }
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ pub mod env;
4949pub mod ext;
5050pub mod fd;
5151pub mod fs;
52+ pub mod futex;
5253pub mod io;
5354#[ cfg( target_os = "l4re" ) ]
5455mod l4re;
Original file line number Diff line number Diff line change 11use crate :: sync:: atomic:: AtomicI32 ;
22use crate :: sync:: atomic:: Ordering :: { Acquire , Release } ;
3+ use crate :: sys:: futex:: { futex_wait, futex_wake} ;
34use crate :: time:: Duration ;
45
56const PARKED : i32 = -1 ;
@@ -71,37 +72,3 @@ impl Parker {
7172 }
7273 }
7374}
74-
75- fn futex_wait ( futex : & AtomicI32 , expected : i32 , timeout : Option < Duration > ) {
76- let timespec;
77- let timespec_ptr = match timeout {
78- Some ( timeout) => {
79- timespec = libc:: timespec {
80- tv_sec : timeout. as_secs ( ) as _ ,
81- tv_nsec : timeout. subsec_nanos ( ) as _ ,
82- } ;
83- & timespec as * const libc:: timespec
84- }
85- None => crate :: ptr:: null ( ) ,
86- } ;
87- unsafe {
88- libc:: syscall (
89- libc:: SYS_futex ,
90- futex as * const AtomicI32 ,
91- libc:: FUTEX_WAIT | libc:: FUTEX_PRIVATE_FLAG ,
92- expected,
93- timespec_ptr,
94- ) ;
95- }
96- }
97-
98- fn futex_wake ( futex : & AtomicI32 ) {
99- unsafe {
100- libc:: syscall (
101- libc:: SYS_futex ,
102- futex as * const AtomicI32 ,
103- libc:: FUTEX_WAKE | libc:: FUTEX_PRIVATE_FLAG ,
104- 1 ,
105- ) ;
106- }
107- }
Original file line number Diff line number Diff line change 11cfg_if:: cfg_if! {
22 if #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] {
3- mod linux ;
4- pub use linux :: Parker ;
3+ mod futex ;
4+ pub use futex :: Parker ;
55 } else {
66 mod generic;
77 pub use generic:: Parker ;
You can’t perform that action at this time.
0 commit comments