mirror of
https://github.com/wez/wezterm.git
synced 2024-09-20 03:09:06 +03:00
condvar for session release
This commit is contained in:
parent
b899c81d19
commit
ac4d1a2a26
@ -10,7 +10,7 @@ use portable_pty::{CommandBuilder, PtySize};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
use tmux_cc::*;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
@ -25,6 +25,7 @@ pub(crate) struct TmuxRemotePane {
|
||||
// members for local
|
||||
pub local_pane_id: PaneId,
|
||||
pub tx: flume::Sender<String>,
|
||||
pub active_lock: Arc<(Mutex<bool>, Condvar)>,
|
||||
// members sync with remote
|
||||
pub session_id: TmuxSessionId,
|
||||
pub window_id: TmuxWindowId,
|
||||
|
@ -10,7 +10,7 @@ use anyhow::anyhow;
|
||||
use portable_pty::{MasterPty, PtySize};
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
use tmux_cc::*;
|
||||
|
||||
pub(crate) trait TmuxCommand: Send {
|
||||
@ -95,9 +95,12 @@ impl TmuxDomainState {
|
||||
|
||||
let local_pane_id = alloc_pane_id();
|
||||
let channel = flume::unbounded::<String>();
|
||||
let active_lock = Arc::new((Mutex::new(false), Condvar::new()));
|
||||
|
||||
let ref_pane = Arc::new(Mutex::new(TmuxRemotePane {
|
||||
local_pane_id,
|
||||
tx: channel.0.clone(),
|
||||
active_lock: active_lock.clone(),
|
||||
session_id: pane.session_id,
|
||||
window_id: pane.window_id,
|
||||
pane_id: pane.pane_id,
|
||||
@ -116,6 +119,7 @@ impl TmuxDomainState {
|
||||
|
||||
let pane_pty = TmuxPty {
|
||||
rx: channel.1.clone(),
|
||||
active_lock: active_lock.clone(),
|
||||
master_pane: ref_pane,
|
||||
};
|
||||
let writer = pane_pty.try_clone_writer().unwrap();
|
||||
|
@ -1,6 +1,9 @@
|
||||
use flume;
|
||||
use portable_pty::{Child, MasterPty};
|
||||
use std::io::{Read, Write};
|
||||
use portable_pty::{Child, ExitStatus, MasterPty};
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
sync::{Arc, Condvar, Mutex},
|
||||
};
|
||||
|
||||
use crate::tmux::RefTmuxRemotePane;
|
||||
|
||||
@ -26,6 +29,7 @@ impl Read for TmuxReader {
|
||||
pub(crate) struct TmuxPty {
|
||||
pub master_pane: RefTmuxRemotePane,
|
||||
pub rx: flume::Receiver<String>,
|
||||
pub active_lock: Arc<(Mutex<bool>, Condvar)>,
|
||||
// TODO: wx
|
||||
}
|
||||
|
||||
@ -50,7 +54,12 @@ impl Child for TmuxPty {
|
||||
}
|
||||
|
||||
fn wait(&mut self) -> std::io::Result<portable_pty::ExitStatus> {
|
||||
loop {}
|
||||
let (lock, var) = &*self.active_lock;
|
||||
let mut released = lock.lock().unwrap();
|
||||
while !*released {
|
||||
released = var.wait(released).unwrap();
|
||||
}
|
||||
return Ok(ExitStatus::with_exit_code(0));
|
||||
}
|
||||
|
||||
fn process_id(&self) -> Option<u32> {
|
||||
@ -84,6 +93,7 @@ impl MasterPty for TmuxPty {
|
||||
Ok(Box::new(TmuxPty {
|
||||
master_pane: self.master_pane.clone(),
|
||||
rx: self.rx.clone(),
|
||||
active_lock: self.active_lock.clone(),
|
||||
}))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user