Skip to content

Commit

Permalink
Merge pull request #70 from alexcrichton/less-sync
Browse files Browse the repository at this point in the history
Remove dependency on the `synchapi` winapi feature
  • Loading branch information
Amanieu authored Apr 27, 2018
2 parents 5bbf7db + 3fecbdf commit 357488b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ libc = "0.2.27"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winnt", "ntstatus", "minwindef",
"winerror", "winbase", "synchapi", "errhandlingapi", "handleapi"] }
"winerror", "winbase", "errhandlingapi", "handleapi"] }

[features]
nightly = []
Expand Down
18 changes: 17 additions & 1 deletion core/src/spinwait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ use std::sync::atomic::spin_loop_hint;
#[cfg(windows)]
#[inline]
fn thread_yield() {
// Note that this is manually defined here rather than using the definition
// through `winapi`. The `winapi` definition comes from the `synchapi`
// header which enables the "synchronization.lib" library. It turns out,
// however that `Sleep` comes from `kernel32.dll` so this activation isn't
// necessary.
//
// This was originally identified in rust-lang/rust where on MinGW the
// libsynchronization.a library pulls in a dependency on a newer DLL not
// present in older versions of Windows. (see rust-lang/rust#49438)
//
// This is a bit of a hack for now and ideally we'd fix MinGW's own import
// libraries, but that'll probably take a lot longer than patching this here
// and avoiding the `synchapi` feature entirely.
extern "system" {
fn Sleep(a: winapi::shared::minwindef::DWORD);
}
unsafe {
// We don't use SwitchToThread here because it doesn't consider all
// threads in the system and the thread we are waiting for may not get
// selected.
winapi::um::synchapi::Sleep(0);
Sleep(0);
}
}
#[cfg(unix)]
Expand Down

0 comments on commit 357488b

Please sign in to comment.