dap: Wrap Child directly in a mutex rather than through Option<_> (#40192)

Release Notes:

- N/A
This commit is contained in:
Jakub Konka
2025-10-15 17:14:04 +02:00
committed by GitHub
parent 85c2dc909d
commit d6c9d00a4c
+5 -10
View File
@@ -649,7 +649,7 @@ impl Drop for TcpTransport {
} }
pub struct StdioTransport { pub struct StdioTransport {
process: Mutex<Option<Child>>, process: Mutex<Child>,
_stderr_task: Option<Task<()>>, _stderr_task: Option<Task<()>>,
} }
@@ -684,7 +684,7 @@ impl StdioTransport {
)) ))
}); });
let process = Mutex::new(Some(process)); let process = Mutex::new(process);
Ok(Self { Ok(Self {
process, process,
@@ -699,9 +699,7 @@ impl Transport for StdioTransport {
} }
fn kill(&mut self) { fn kill(&mut self) {
if let Some(process) = &mut *self.process.lock() { self.process.lock().kill();
process.kill();
}
} }
fn connect( fn connect(
@@ -713,8 +711,7 @@ impl Transport for StdioTransport {
)>, )>,
> { > {
let result = util::maybe!({ let result = util::maybe!({
let mut guard = self.process.lock(); let mut process = self.process.lock();
let process = guard.as_mut().context("oops")?;
Ok(( Ok((
Box::new(process.stdin.take().context("Cannot reconnect")?) as _, Box::new(process.stdin.take().context("Cannot reconnect")?) as _,
Box::new(process.stdout.take().context("Cannot reconnect")?) as _, Box::new(process.stdout.take().context("Cannot reconnect")?) as _,
@@ -730,9 +727,7 @@ impl Transport for StdioTransport {
impl Drop for StdioTransport { impl Drop for StdioTransport {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(process) = &mut *self.process.lock() { self.process.lock().kill();
process.kill();
}
} }
} }