about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorAndy Russell <arussell123@gmail.com>2020-01-04 16:46:47 -0500
committerAndy Russell <arussell123@gmail.com>2020-01-11 20:56:46 -0500
commit7b564c67deb6f5e9d7102871d63a9ad3d7161278 (patch)
treeb43fded1c4297cb96a2c7825044d66def77f851c /src/librustc_errors
parent1389494ac145a84dba025ff65969f7ab150c3f02 (diff)
downloadrust-7b564c67deb6f5e9d7102871d63a9ad3d7161278.tar.gz
rust-7b564c67deb6f5e9d7102871d63a9ad3d7161278.zip
use winapi for non-stdlib Windows bindings
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/Cargo.toml3
-rw-r--r--src/librustc_errors/lock.rs27
2 files changed, 8 insertions, 22 deletions
diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml
index 0d0989677c5..01ea80659d6 100644
--- a/src/librustc_errors/Cargo.toml
+++ b/src/librustc_errors/Cargo.toml
@@ -19,3 +19,6 @@ atty = "0.2"
 termcolor = "1.0"
 annotate-snippets = "0.6.1"
 term_size = "0.3.1"
+
+[target.'cfg(windows)'.dependencies]
+winapi = { version = "0.3", features = ["handleapi", "synchapi", "winbase"] }
diff --git a/src/librustc_errors/lock.rs b/src/librustc_errors/lock.rs
index 198a9c12406..a73472021d4 100644
--- a/src/librustc_errors/lock.rs
+++ b/src/librustc_errors/lock.rs
@@ -12,31 +12,14 @@
 use std::any::Any;
 
 #[cfg(windows)]
-#[allow(nonstandard_style)]
 pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
     use std::ffi::CString;
     use std::io;
 
-    type LPSECURITY_ATTRIBUTES = *mut u8;
-    type BOOL = i32;
-    type LPCSTR = *const u8;
-    type HANDLE = *mut u8;
-    type DWORD = u32;
-
-    const INFINITE: DWORD = !0;
-    const WAIT_OBJECT_0: DWORD = 0;
-    const WAIT_ABANDONED: DWORD = 0x00000080;
-
-    extern "system" {
-        fn CreateMutexA(
-            lpMutexAttributes: LPSECURITY_ATTRIBUTES,
-            bInitialOwner: BOOL,
-            lpName: LPCSTR,
-        ) -> HANDLE;
-        fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
-        fn ReleaseMutex(hMutex: HANDLE) -> BOOL;
-        fn CloseHandle(hObject: HANDLE) -> BOOL;
-    }
+    use winapi::shared::ntdef::HANDLE;
+    use winapi::um::handleapi::CloseHandle;
+    use winapi::um::synchapi::{CreateMutexA, ReleaseMutex, WaitForSingleObject};
+    use winapi::um::winbase::{INFINITE, WAIT_ABANDONED, WAIT_OBJECT_0};
 
     struct Handle(HANDLE);
 
@@ -65,7 +48,7 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
         //
         // This will silently create one if it doesn't already exist, or it'll
         // open up a handle to one if it already exists.
-        let mutex = CreateMutexA(std::ptr::null_mut(), 0, cname.as_ptr() as *const u8);
+        let mutex = CreateMutexA(std::ptr::null_mut(), 0, cname.as_ptr());
         if mutex.is_null() {
             panic!(
                 "failed to create global mutex named `{}`: {}",