@@ -10,6 +10,7 @@ use core::sync::atomic::{
10
10
} ;
11
11
use core:: time:: Duration ;
12
12
13
+ pub unsafe trait Futex { }
13
14
pub unsafe trait Waitable {
14
15
type Atomic ;
15
16
}
@@ -19,6 +20,7 @@ macro_rules! unsafe_waitable_int {
19
20
unsafe impl Waitable for $int {
20
21
type Atomic = $atomic;
21
22
}
23
+ unsafe impl Futex for $atomic { }
22
24
) *
23
25
} ;
24
26
}
@@ -41,6 +43,7 @@ unsafe impl<T> Waitable for *const T {
41
43
unsafe impl < T > Waitable for * mut T {
42
44
type Atomic = AtomicPtr < T > ;
43
45
}
46
+ unsafe impl < T > Futex for AtomicPtr < T > { }
44
47
45
48
pub fn wait_on_address < W : Waitable > (
46
49
address : & W :: Atomic ,
@@ -56,14 +59,14 @@ pub fn wait_on_address<W: Waitable>(
56
59
}
57
60
}
58
61
59
- pub fn wake_by_address_single < T > ( address : & T ) {
62
+ pub fn wake_by_address_single < T : Futex > ( address : & T ) {
60
63
unsafe {
61
64
let addr = ptr:: from_ref ( address) . cast :: < c_void > ( ) ;
62
65
c:: WakeByAddressSingle ( addr) ;
63
66
}
64
67
}
65
68
66
- pub fn wake_by_address_all < T > ( address : & T ) {
69
+ pub fn wake_by_address_all < T : Futex > ( address : & T ) {
67
70
unsafe {
68
71
let addr = ptr:: from_ref ( address) . cast :: < c_void > ( ) ;
69
72
c:: WakeByAddressAll ( addr) ;
@@ -75,11 +78,11 @@ pub fn futex_wait<W: Waitable>(futex: &W::Atomic, expected: W, timeout: Option<D
75
78
wait_on_address ( futex, expected, timeout) || api:: get_last_error ( ) != WinError :: TIMEOUT
76
79
}
77
80
78
- pub fn futex_wake < T > ( futex : & T ) -> bool {
81
+ pub fn futex_wake < T : Futex > ( futex : & T ) -> bool {
79
82
wake_by_address_single ( futex) ;
80
83
false
81
84
}
82
85
83
- pub fn futex_wake_all < T > ( futex : & T ) {
86
+ pub fn futex_wake_all < T : Futex > ( futex : & T ) {
84
87
wake_by_address_all ( futex)
85
88
}
0 commit comments