mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Use jod_thread
This commit is contained in:
parent
39706a5786
commit
7f7a16675d
3 changed files with 16 additions and 17 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1076,6 +1076,7 @@ name = "ra_proc_macro"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
"jod-thread",
|
||||||
"log",
|
"log",
|
||||||
"ra_tt",
|
"ra_tt",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -14,3 +14,4 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
crossbeam-channel = "0.4.0"
|
crossbeam-channel = "0.4.0"
|
||||||
|
jod-thread = "0.1.1"
|
||||||
|
|
|
@ -12,7 +12,6 @@ use std::{
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Child, Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
thread::{spawn, JoinHandle},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
@ -22,8 +21,18 @@ pub(crate) struct ProcMacroProcessSrv {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ProcMacroProcessThread {
|
pub(crate) struct ProcMacroProcessThread {
|
||||||
handle: Option<JoinHandle<()>>,
|
// XXX: drop order is significant
|
||||||
sender: Sender<Task>,
|
sender: SenderGuard,
|
||||||
|
handle: jod_thread::JoinHandle<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct SenderGuard(pub Sender<Task>);
|
||||||
|
|
||||||
|
impl std::ops::Drop for SenderGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = self.0.send(Task::Close);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Task {
|
enum Task {
|
||||||
|
@ -62,18 +71,6 @@ impl Process {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Drop for ProcMacroProcessThread {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if let Some(handle) = self.handle.take() {
|
|
||||||
let _ = self.sender.send(Task::Close);
|
|
||||||
|
|
||||||
// Join the thread, it should finish shortly. We don't really care
|
|
||||||
// whether it panicked, so it is safe to ignore the result
|
|
||||||
let _ = handle.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ProcMacroProcessSrv {
|
impl ProcMacroProcessSrv {
|
||||||
pub fn run(
|
pub fn run(
|
||||||
process_path: &Path,
|
process_path: &Path,
|
||||||
|
@ -81,12 +78,12 @@ impl ProcMacroProcessSrv {
|
||||||
let process = Process::run(process_path)?;
|
let process = Process::run(process_path)?;
|
||||||
|
|
||||||
let (task_tx, task_rx) = bounded(0);
|
let (task_tx, task_rx) = bounded(0);
|
||||||
let handle = spawn(move || {
|
let handle = jod_thread::spawn(move || {
|
||||||
client_loop(task_rx, process);
|
client_loop(task_rx, process);
|
||||||
});
|
});
|
||||||
|
|
||||||
let srv = ProcMacroProcessSrv { inner: Some(task_tx.clone()) };
|
let srv = ProcMacroProcessSrv { inner: Some(task_tx.clone()) };
|
||||||
let thread = ProcMacroProcessThread { handle: Some(handle), sender: task_tx };
|
let thread = ProcMacroProcessThread { handle, sender: SenderGuard(task_tx) };
|
||||||
|
|
||||||
Ok((thread, srv))
|
Ok((thread, srv))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue