@@ -52,25 +52,6 @@ pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -
52
52
}
53
53
}
54
54
55
- #[ cfg( target_os = "emscripten" ) ]
56
- pub fn futex_wait ( futex : & AtomicU32 , expected : u32 , timeout : Option < Duration > ) {
57
- extern "C" {
58
- fn emscripten_futex_wait (
59
- addr : * const AtomicU32 ,
60
- val : libc:: c_uint ,
61
- max_wait_ms : libc:: c_double ,
62
- ) -> libc:: c_int ;
63
- }
64
-
65
- unsafe {
66
- emscripten_futex_wait (
67
- futex,
68
- expected,
69
- timeout. map_or ( crate :: f64:: INFINITY , |d| d. as_secs_f64 ( ) * 1000.0 ) ,
70
- ) ;
71
- }
72
- }
73
-
74
55
/// Wake up one thread that's blocked on futex_wait on this futex.
75
56
///
76
57
/// Returns true if this actually woke up such a thread,
@@ -101,10 +82,32 @@ pub fn futex_wake_all(futex: &AtomicU32) {
101
82
}
102
83
103
84
#[ cfg( target_os = "emscripten" ) ]
104
- pub fn futex_wake ( futex : & AtomicU32 ) -> bool {
105
- extern "C" {
106
- fn emscripten_futex_wake ( addr : * const AtomicU32 , count : libc:: c_int ) -> libc:: c_int ;
85
+ extern "C" {
86
+ fn emscripten_futex_wake ( addr : * const AtomicU32 , count : libc:: c_int ) -> libc:: c_int ;
87
+ fn emscripten_futex_wait (
88
+ addr : * const AtomicU32 ,
89
+ val : libc:: c_uint ,
90
+ max_wait_ms : libc:: c_double ,
91
+ ) -> libc:: c_int ;
92
+ }
93
+
94
+ #[ cfg( target_os = "emscripten" ) ]
95
+ pub fn futex_wait ( futex : & AtomicU32 , expected : u32 , timeout : Option < Duration > ) -> bool {
96
+ unsafe {
97
+ emscripten_futex_wait (
98
+ futex,
99
+ expected,
100
+ timeout. map_or ( f64:: INFINITY , |d| d. as_secs_f64 ( ) * 1000.0 ) ,
101
+ ) != -libc:: ETIMEDOUT
107
102
}
103
+ }
108
104
105
+ #[ cfg( target_os = "emscripten" ) ]
106
+ pub fn futex_wake ( futex : & AtomicU32 ) -> bool {
109
107
unsafe { emscripten_futex_wake ( futex, 1 ) > 0 }
110
108
}
109
+
110
+ #[ cfg( target_os = "emscripten" ) ]
111
+ pub fn futex_wake_all ( futex : & AtomicU32 ) {
112
+ unsafe { emscripten_futex_wake ( futex, i32:: MAX ) } ;
113
+ }
0 commit comments