File tree 4 files changed +42
-36
lines changed
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;
49
49
pub mod ext;
50
50
pub mod fd;
51
51
pub mod fs;
52
+ pub mod futex;
52
53
pub mod io;
53
54
#[ cfg( target_os = "l4re" ) ]
54
55
mod l4re;
Original file line number Diff line number Diff line change 1
1
use crate :: sync:: atomic:: AtomicI32 ;
2
2
use crate :: sync:: atomic:: Ordering :: { Acquire , Release } ;
3
+ use crate :: sys:: futex:: { futex_wait, futex_wake} ;
3
4
use crate :: time:: Duration ;
4
5
5
6
const PARKED : i32 = -1 ;
@@ -70,37 +71,3 @@ impl Parker {
70
71
}
71
72
}
72
73
}
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 1
1
cfg_if:: cfg_if! {
2
2
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 ;
5
5
} else {
6
6
mod generic;
7
7
pub use generic:: Parker ;
You can’t perform that action at this time.
0 commit comments