]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_errors/lock.rs
Do not base path to append extension
[rust.git] / src / librustc_errors / lock.rs
index 25a27d2cbd884d953c3e28e64c7f043d2db5e519..a73472021d4127bd246b1543c8d1d9d22eba1dcb 100644 (file)
 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);
 
@@ -64,11 +48,13 @@ fn drop(&mut self) {
         //
         // 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 `{}`: {}",
-                   name,
-                   io::Error::last_os_error());
+            panic!(
+                "failed to create global mutex named `{}`: {}",
+                name,
+                io::Error::last_os_error()
+            );
         }
         let mutex = Handle(mutex);
 
@@ -86,11 +72,13 @@ fn drop(&mut self) {
         match WaitForSingleObject(mutex.0, INFINITE) {
             WAIT_OBJECT_0 | WAIT_ABANDONED => {}
             code => {
-                panic!("WaitForSingleObject failed on global mutex named \
+                panic!(
+                    "WaitForSingleObject failed on global mutex named \
                         `{}`: {} (ret={:x})",
-                       name,
-                       io::Error::last_os_error(),
-                       code);
+                    name,
+                    io::Error::last_os_error(),
+                    code
+                );
             }
         }