mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
more properly fix cond notify on Promise::drop
This commit is contained in:
parent
d061303bb4
commit
55caafb0c4
@ -73,6 +73,21 @@ impl<T> Default for Promise<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for Promise<T> {
|
||||
fn drop(&mut self) {
|
||||
if let PromiseState::Waiting(core) = &mut self.state {
|
||||
let err = Err(failure::err_msg("Promise was dropped before completion"));
|
||||
let mut locked = core.data.lock().unwrap();
|
||||
if let Some(func) = locked.propagate.take() {
|
||||
func(err);
|
||||
} else {
|
||||
locked.result = Some(err);
|
||||
}
|
||||
core.cond.notify_one();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Promise<T> {
|
||||
pub fn new() -> Self {
|
||||
let core = Arc::new(Core {
|
||||
|
@ -56,12 +56,9 @@ macro_rules! rpc {
|
||||
};
|
||||
}
|
||||
|
||||
fn client_thread_inner(
|
||||
mut stream: Box<dyn ReadAndWrite>,
|
||||
rx: Receiver<ReaderMessage>,
|
||||
promises: &mut HashMap<u64, Promise<Pdu>>,
|
||||
) -> Fallible<()> {
|
||||
fn client_thread(mut stream: Box<dyn ReadAndWrite>, rx: Receiver<ReaderMessage>) -> Fallible<()> {
|
||||
let mut next_serial = 0u64;
|
||||
let mut promises = HashMap::new();
|
||||
loop {
|
||||
let msg = if promises.is_empty() {
|
||||
// If we don't have any results to read back, then we can and
|
||||
@ -105,21 +102,6 @@ fn client_thread_inner(
|
||||
}
|
||||
}
|
||||
|
||||
fn client_thread(stream: Box<dyn ReadAndWrite>, rx: Receiver<ReaderMessage>) -> Fallible<()> {
|
||||
let mut promises = HashMap::new();
|
||||
|
||||
let res = client_thread_inner(stream, rx, &mut promises);
|
||||
|
||||
// be sure to fail any extant promises: on macos at least, the
|
||||
// rust condvar implementation doesn't wake any waiters when
|
||||
// it is destroyed, which can lead to a deadlock on shutdown.
|
||||
for promise in promises.values_mut() {
|
||||
promise.err(err_msg("client thread ended"));
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(stream: Box<dyn ReadAndWrite>) -> Self {
|
||||
let (sender, receiver) = channel();
|
||||
|
Loading…
Reference in New Issue
Block a user