]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/sys/windows/process.rs
Rollup merge of #84734 - tmandry:compiletest-needs-unwind, r=Mark-Simulacrum
[rust.git] / library / std / src / sys / windows / process.rs
index 30bbfdd0dd1e2412d231f8fa4aaa92630a91a79d..a5799606142ec2b44e850399772a8fb14e84e3f2 100644 (file)
@@ -19,9 +19,9 @@
 use crate::sys::cvt;
 use crate::sys::fs::{File, OpenOptions};
 use crate::sys::handle::Handle;
-use crate::sys::mutex::Mutex;
 use crate::sys::pipe::{self, AnonPipe};
 use crate::sys::stdio;
+use crate::sys_common::mutex::StaticMutex;
 use crate::sys_common::process::{CommandEnv, CommandEnvs};
 use crate::sys_common::AsInner;
 
@@ -94,10 +94,6 @@ pub struct StdioPipes {
     pub stderr: Option<AnonPipe>,
 }
 
-struct DropGuard<'a> {
-    lock: &'a Mutex,
-}
-
 impl Command {
     pub fn new(program: &OsStr) -> Command {
         Command {
@@ -209,8 +205,9 @@ pub fn spawn(
         //
         // For more information, msdn also has an article about this race:
         // http://support.microsoft.com/kb/315939
-        static CREATE_PROCESS_LOCK: Mutex = Mutex::new();
-        let _guard = DropGuard::new(&CREATE_PROCESS_LOCK);
+        static CREATE_PROCESS_LOCK: StaticMutex = StaticMutex::new();
+
+        let _guard = unsafe { CREATE_PROCESS_LOCK.lock() };
 
         let mut pipes = StdioPipes { stdin: None, stdout: None, stderr: None };
         let null = Stdio::Null;
@@ -259,23 +256,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-impl<'a> DropGuard<'a> {
-    fn new(lock: &'a Mutex) -> DropGuard<'a> {
-        unsafe {
-            lock.lock();
-            DropGuard { lock }
-        }
-    }
-}
-
-impl<'a> Drop for DropGuard<'a> {
-    fn drop(&mut self) {
-        unsafe {
-            self.lock.unlock();
-        }
-    }
-}
-
 impl Stdio {
     fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
         match *self {