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 ;
@@ -71,37 +72,3 @@ impl Parker {
71
72
}
72
73
}
73
74
}
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 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