Merge #9519
9519: Explicitly name all spawned threads r=weirdsmiley a=weirdsmiley Fixes: [#9385](https://github.com/rust-analyzer/rust-analyzer/issues/9385) The thread name is shown in debugger as well as panic messages and this patch makes it easier to follow a thread instead of looking through full backtrace, by naming all spawned threads according to their functioning. Co-authored-by: Manas <manas18244@iiitd.ac.in>
This commit is contained in:
commit
9f24cc7126
@ -67,7 +67,10 @@ pub fn spawn(
|
||||
) -> FlycheckHandle {
|
||||
let actor = FlycheckActor::new(id, sender, config, workspace_root);
|
||||
let (sender, receiver) = unbounded::<Restart>();
|
||||
let thread = jod_thread::spawn(move || actor.run(receiver));
|
||||
let thread = jod_thread::Builder::new()
|
||||
.name("FlycheckThread".to_owned())
|
||||
.spawn(move || actor.run(receiver))
|
||||
.expect("failed to spawn thread");
|
||||
FlycheckHandle { sender, thread }
|
||||
}
|
||||
|
||||
@ -266,7 +269,10 @@ fn spawn(mut child: JodChild) -> CargoHandle {
|
||||
let child_stdout = child.stdout.take().unwrap();
|
||||
let (sender, receiver) = unbounded();
|
||||
let actor = CargoActor::new(child_stdout, sender);
|
||||
let thread = jod_thread::spawn(move || actor.run());
|
||||
let thread = jod_thread::Builder::new()
|
||||
.name("CargoHandleThread".to_owned())
|
||||
.spawn(move || actor.run())
|
||||
.expect("failed to spawn thread");
|
||||
CargoHandle { child, thread, receiver }
|
||||
}
|
||||
fn join(mut self) -> io::Result<()> {
|
||||
|
@ -37,9 +37,12 @@ pub(crate) fn run(
|
||||
let process = Process::run(process_path, args)?;
|
||||
|
||||
let (task_tx, task_rx) = bounded(0);
|
||||
let handle = jod_thread::spawn(move || {
|
||||
client_loop(task_rx, process);
|
||||
});
|
||||
let handle = jod_thread::Builder::new()
|
||||
.name("ProcMacroClientThread".to_owned())
|
||||
.spawn(move || {
|
||||
client_loop(task_rx, process);
|
||||
})
|
||||
.expect("failed to spawn thread");
|
||||
|
||||
let task_tx = Arc::new(task_tx);
|
||||
let srv = ProcMacroProcessSrv { inner: Arc::downgrade(&task_tx) };
|
||||
|
@ -181,21 +181,24 @@ fn run_bridge_and_client<D: Copy + Send + 'static>(
|
||||
let (req_tx, req_rx) = channel();
|
||||
let (res_tx, res_rx) = channel();
|
||||
|
||||
let join_handle = thread::spawn(move || {
|
||||
let mut dispatch = |b| {
|
||||
req_tx.send(b).unwrap();
|
||||
res_rx.recv().unwrap()
|
||||
};
|
||||
let join_handle = thread::Builder::new()
|
||||
.name("DispatchThread".to_owned())
|
||||
.spawn(move || {
|
||||
let mut dispatch = |b| {
|
||||
req_tx.send(b).unwrap();
|
||||
res_rx.recv().unwrap()
|
||||
};
|
||||
|
||||
run_client(
|
||||
Bridge {
|
||||
cached_buffer: input,
|
||||
dispatch: (&mut dispatch).into(),
|
||||
force_show_panics,
|
||||
},
|
||||
client_data,
|
||||
)
|
||||
});
|
||||
run_client(
|
||||
Bridge {
|
||||
cached_buffer: input,
|
||||
dispatch: (&mut dispatch).into(),
|
||||
force_show_panics,
|
||||
},
|
||||
client_data,
|
||||
)
|
||||
})
|
||||
.expect("failed to spawn thread");
|
||||
|
||||
for b in req_rx {
|
||||
res_tx.send(dispatcher.dispatch(b)).unwrap();
|
||||
@ -227,33 +230,36 @@ enum State<T> {
|
||||
|
||||
let server_thread = thread::current();
|
||||
let state2 = state.clone();
|
||||
let join_handle = thread::spawn(move || {
|
||||
let mut dispatch = |b| {
|
||||
*state2.lock().unwrap() = State::Req(b);
|
||||
server_thread.unpark();
|
||||
loop {
|
||||
thread::park();
|
||||
if let State::Res(b) = &mut *state2.lock().unwrap() {
|
||||
break b.take();
|
||||
let join_handle = thread::Builder::new()
|
||||
.name("ServerThread".to_owned())
|
||||
.spawn(move || {
|
||||
let mut dispatch = |b| {
|
||||
*state2.lock().unwrap() = State::Req(b);
|
||||
server_thread.unpark();
|
||||
loop {
|
||||
thread::park();
|
||||
if let State::Res(b) = &mut *state2.lock().unwrap() {
|
||||
break b.take();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let r = run_client(
|
||||
Bridge {
|
||||
cached_buffer: input,
|
||||
dispatch: (&mut dispatch).into(),
|
||||
force_show_panics,
|
||||
},
|
||||
client_data,
|
||||
);
|
||||
let r = run_client(
|
||||
Bridge {
|
||||
cached_buffer: input,
|
||||
dispatch: (&mut dispatch).into(),
|
||||
force_show_panics,
|
||||
},
|
||||
client_data,
|
||||
);
|
||||
|
||||
// Wake up the server so it can exit the dispatch loop.
|
||||
drop(state2);
|
||||
server_thread.unpark();
|
||||
// Wake up the server so it can exit the dispatch loop.
|
||||
drop(state2);
|
||||
server_thread.unpark();
|
||||
|
||||
r
|
||||
});
|
||||
r
|
||||
})
|
||||
.expect("failed to spawn thread");
|
||||
|
||||
// Check whether `state2` was dropped, to know when to stop.
|
||||
while Arc::get_mut(&mut state).is_none() {
|
||||
|
@ -31,7 +31,10 @@ impl loader::Handle for NotifyHandle {
|
||||
fn spawn(sender: loader::Sender) -> NotifyHandle {
|
||||
let actor = NotifyActor::new(sender);
|
||||
let (sender, receiver) = unbounded::<Message>();
|
||||
let thread = jod_thread::spawn(move || actor.run(receiver));
|
||||
let thread = jod_thread::Builder::new()
|
||||
.name("LoaderThread".to_owned())
|
||||
.spawn(move || actor.run(receiver))
|
||||
.expect("failed to spawn thread");
|
||||
NotifyHandle { sender, thread }
|
||||
}
|
||||
fn set_config(&mut self, config: loader::Config) {
|
||||
|
Loading…
Reference in New Issue
Block a user