Rollup merge of #84663 - CDirkx:dropguard, r=Mark-Simulacrum
Remove `DropGuard` in `sys::windows::process` and use `StaticMutex` instead `StaticMutex` is a mutex that when locked provides a guard that unlocks the mutex again when dropped, thus provides the exact same functionality as `DropGuard`. `StaticMutex` is used in more places, and is thus preferred over an ad-hoc construct like `DropGuard`. ````@rustbot```` label: +T-libs-impl
This commit is contained in:
commit
ccd04a5281
1 changed files with 4 additions and 24 deletions
|
@ -19,9 +19,9 @@ use crate::sys::c;
|
||||||
use crate::sys::cvt;
|
use crate::sys::cvt;
|
||||||
use crate::sys::fs::{File, OpenOptions};
|
use crate::sys::fs::{File, OpenOptions};
|
||||||
use crate::sys::handle::Handle;
|
use crate::sys::handle::Handle;
|
||||||
use crate::sys::mutex::Mutex;
|
|
||||||
use crate::sys::pipe::{self, AnonPipe};
|
use crate::sys::pipe::{self, AnonPipe};
|
||||||
use crate::sys::stdio;
|
use crate::sys::stdio;
|
||||||
|
use crate::sys_common::mutex::StaticMutex;
|
||||||
use crate::sys_common::process::{CommandEnv, CommandEnvs};
|
use crate::sys_common::process::{CommandEnv, CommandEnvs};
|
||||||
use crate::sys_common::AsInner;
|
use crate::sys_common::AsInner;
|
||||||
|
|
||||||
|
@ -94,10 +94,6 @@ pub struct StdioPipes {
|
||||||
pub stderr: Option<AnonPipe>,
|
pub stderr: Option<AnonPipe>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DropGuard<'a> {
|
|
||||||
lock: &'a Mutex,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn new(program: &OsStr) -> Command {
|
pub fn new(program: &OsStr) -> Command {
|
||||||
Command {
|
Command {
|
||||||
|
@ -209,8 +205,9 @@ impl Command {
|
||||||
//
|
//
|
||||||
// For more information, msdn also has an article about this race:
|
// For more information, msdn also has an article about this race:
|
||||||
// http://support.microsoft.com/kb/315939
|
// http://support.microsoft.com/kb/315939
|
||||||
static CREATE_PROCESS_LOCK: Mutex = Mutex::new();
|
static CREATE_PROCESS_LOCK: StaticMutex = StaticMutex::new();
|
||||||
let _guard = DropGuard::new(&CREATE_PROCESS_LOCK);
|
|
||||||
|
let _guard = unsafe { CREATE_PROCESS_LOCK.lock() };
|
||||||
|
|
||||||
let mut pipes = StdioPipes { stdin: None, stdout: None, stderr: None };
|
let mut pipes = StdioPipes { stdin: None, stdout: None, stderr: None };
|
||||||
let null = Stdio::Null;
|
let null = Stdio::Null;
|
||||||
|
@ -259,23 +256,6 @@ impl fmt::Debug for Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
impl Stdio {
|
||||||
fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
|
fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option<AnonPipe>) -> io::Result<Handle> {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue