@@ -10,6 +10,7 @@ use core::sync::atomic::{
1010} ;
1111use core:: time:: Duration ;
1212
13+ pub unsafe trait Futex { }
1314pub unsafe trait Waitable {
1415 type Atomic ;
1516}
@@ -19,6 +20,7 @@ macro_rules! unsafe_waitable_int {
1920 unsafe impl Waitable for $int {
2021 type Atomic = $atomic;
2122 }
23+ unsafe impl Futex for $atomic { }
2224 ) *
2325 } ;
2426}
@@ -41,6 +43,7 @@ unsafe impl<T> Waitable for *const T {
4143unsafe impl < T > Waitable for * mut T {
4244 type Atomic = AtomicPtr < T > ;
4345}
46+ unsafe impl < T > Futex for AtomicPtr < T > { }
4447
4548pub fn wait_on_address < W : Waitable > (
4649 address : & W :: Atomic ,
@@ -56,14 +59,14 @@ pub fn wait_on_address<W: Waitable>(
5659 }
5760}
5861
59- pub fn wake_by_address_single < T > ( address : & T ) {
62+ pub fn wake_by_address_single < T : Futex > ( address : & T ) {
6063 unsafe {
6164 let addr = ptr:: from_ref ( address) . cast :: < c_void > ( ) ;
6265 c:: WakeByAddressSingle ( addr) ;
6366 }
6467}
6568
66- pub fn wake_by_address_all < T > ( address : & T ) {
69+ pub fn wake_by_address_all < T : Futex > ( address : & T ) {
6770 unsafe {
6871 let addr = ptr:: from_ref ( address) . cast :: < c_void > ( ) ;
6972 c:: WakeByAddressAll ( addr) ;
@@ -75,11 +78,11 @@ pub fn futex_wait<W: Waitable>(futex: &W::Atomic, expected: W, timeout: Option<D
7578 wait_on_address ( futex, expected, timeout) || api:: get_last_error ( ) != WinError :: TIMEOUT
7679}
7780
78- pub fn futex_wake < T > ( futex : & T ) -> bool {
81+ pub fn futex_wake < T : Futex > ( futex : & T ) -> bool {
7982 wake_by_address_single ( futex) ;
8083 false
8184}
8285
83- pub fn futex_wake_all < T > ( futex : & T ) {
86+ pub fn futex_wake_all < T : Futex > ( futex : & T ) {
8487 wake_by_address_all ( futex)
8588}
0 commit comments