Skip to content

Commit e3078f8

Browse files
committed
Use raw-dylib for Windows futex APIs
This is a workaround for older mingw `synchronization` import library not working on at least some system.
1 parent 4e1f5d9 commit e3078f8

File tree

1 file changed

+28
-12
lines changed
  • library/std/src/sys/pal/windows

1 file changed

+28
-12
lines changed

library/std/src/sys/pal/windows/c.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,34 @@ compat_fn_with_fallback! {
356356
}
357357
}
358358

359-
#[cfg(not(target_vendor = "win7"))]
360-
#[link(name = "synchronization")]
361-
extern "system" {
362-
pub fn WaitOnAddress(
363-
address: *const c_void,
364-
compareaddress: *const c_void,
365-
addresssize: usize,
366-
dwmilliseconds: u32,
367-
) -> BOOL;
368-
pub fn WakeByAddressSingle(address: *const c_void);
369-
pub fn WakeByAddressAll(address: *const c_void);
370-
}
359+
// Use raw-dylib to import synchronization functions to workaround issues with the older mingw import library.
360+
cfg_if::cfg_if! {
361+
if #[cfg(not(target_vendor = "win7"))] {
362+
#[cfg(target_arch = "x86")]
363+
#[link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib", import_name_type = "undecorated")]
364+
extern "system" {
365+
pub fn WaitOnAddress(
366+
address: *const c_void,
367+
compareaddress: *const c_void,
368+
addresssize: usize,
369+
dwmilliseconds: u32,
370+
) -> BOOL;
371+
pub fn WakeByAddressSingle(address: *const c_void);
372+
pub fn WakeByAddressAll(address: *const c_void);
373+
}
374+
#[cfg(not(target_arch = "x86"))]
375+
#[link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib")]
376+
extern "system" {
377+
pub fn WaitOnAddress(
378+
address: *const c_void,
379+
compareaddress: *const c_void,
380+
addresssize: usize,
381+
dwmilliseconds: u32,
382+
) -> BOOL;
383+
pub fn WakeByAddressSingle(address: *const c_void);
384+
pub fn WakeByAddressAll(address: *const c_void);
385+
}
386+
}}
371387

372388
#[cfg(target_vendor = "win7")]
373389
compat_fn_optional! {

0 commit comments

Comments
 (0)