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 ;
@@ -70,37 +71,3 @@ impl Parker {
7071 }
7172 }
7273}
73-
74- fn futex_wait ( futex : & AtomicI32 , expected : i32 , timeout : Option < Duration > ) {
75- let timespec;
76- let timespec_ptr = match timeout {
77- Some ( timeout) => {
78- timespec = libc:: timespec {
79- tv_sec : timeout. as_secs ( ) as _ ,
80- tv_nsec : timeout. subsec_nanos ( ) as _ ,
81- } ;
82- & timespec as * const libc:: timespec
83- }
84- None => crate :: ptr:: null ( ) ,
85- } ;
86- unsafe {
87- libc:: syscall (
88- libc:: SYS_futex ,
89- futex as * const AtomicI32 ,
90- libc:: FUTEX_WAIT | libc:: FUTEX_PRIVATE_FLAG ,
91- expected,
92- timespec_ptr,
93- ) ;
94- }
95- }
96-
97- fn futex_wake ( futex : & AtomicI32 ) {
98- unsafe {
99- libc:: syscall (
100- libc:: SYS_futex ,
101- futex as * const AtomicI32 ,
102- libc:: FUTEX_WAKE | libc:: FUTEX_PRIVATE_FLAG ,
103- 1 ,
104- ) ;
105- }
106- }
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