thread executor through to mux code

This commit is contained in:
Wez Furlong committed 2019-03-04 20:19:08 +00:00
1 parent ac016c0494
commit aa6cfb00dd
4 files changed
+29 -11

No files matched your search

+11 -6
View File
@@ -136,10 +136,8 @@ impl GuiSystem for GlutinGuiSystem {
Box::new(self.event_loop.poll_tx.clone())
}
fn gui_executor(&self) -> Arc<Executor> {
Arc::new(GlutinGuiExecutor {
tx: self.event_loop.gui_tx.clone(),
})
fn gui_executor(&self) -> Arc<Executor + Sync + Send> {
self.event_loop.gui_executor()
}
fn run_forever(&self) -> Result<(), Error> {
@@ -222,8 +220,15 @@ impl GuiEventLoop {
res
}
fn gui_executor(&self) -> Arc<Executor + Sync + Send> {
Arc::new(GlutinGuiExecutor {
tx: self.gui_tx.clone(),
})
}
pub fn register_tab(&self, tab: &Rc<Tab>) -> Result<(), Error> {
self.mux.add_tab(Box::new(self.poll_tx.clone()), tab)
self.mux
.add_tab(self.gui_executor(), Box::new(self.poll_tx.clone()), tab)
}
fn do_spawn_new_window(
@@ -233,7 +238,7 @@ impl GuiEventLoop {
) -> Result<(), Error> {
let tab = spawn_tab(&config, None)?;
let sender = Box::new(self.poll_tx.clone());
self.mux.add_tab(sender, &tab)?;
self.mux.add_tab(self.gui_executor(), sender, &tab)?;
let events = Self::get().expect("to be called on gui thread");
let window = GliumTerminalWindow::new(&events, &fonts, &config, &tab)?;
+1 -1
View File
@@ -97,7 +97,7 @@ pub trait GuiSystem {
fn pty_sender(&self) -> Box<PtyEventSender>;
fn gui_executor(&self) -> Arc<Executor>;
fn gui_executor(&self) -> Arc<Executor + Sync + Send>;
}
pub mod glutinloop;
+1 -1
View File
@@ -172,7 +172,7 @@ fn spawn_window(
fontconfig: &Rc<FontConfiguration>,
) -> Result<(), Error> {
let tab = spawn_tab(config, cmd)?;
mux.add_tab(gui.pty_sender(), &tab)?;
mux.add_tab(gui.gui_executor(), gui.pty_sender(), &tab)?;
gui.spawn_new_window(config, &fontconfig, &tab)
}
+16 -3
View File
@@ -1,10 +1,12 @@
use crate::futurecore::Spawner;
use crate::guicommon::tabs::{Tab, TabId};
use failure::Error;
use promise::Executor;
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::Read;
use std::rc::Rc;
use std::sync::Arc;
use std::thread;
use term::TerminalHost;
use termwiz::hyperlink::Hyperlink;
@@ -28,6 +30,7 @@ pub trait PtyEventSender: Send {
}
fn read_from_tab_pty(
executor: Arc<Executor>,
spawner: Spawner,
sender: Box<PtyEventSender>,
tab_id: TabId,
@@ -107,17 +110,27 @@ impl Mux {
self.tabs.borrow().get(&tab_id).map(Rc::clone)
}
pub fn add_tab(&self, sender: Box<PtyEventSender>, tab: &Rc<Tab>) -> Result<(), Error> {
pub fn add_tab(
&self,
executor: Arc<Executor + Send + Sync>,
sender: Box<PtyEventSender>,
tab: &Rc<Tab>,
) -> Result<(), Error> {
self.tabs.borrow_mut().insert(tab.tab_id(), Rc::clone(tab));
let reader = tab.reader()?;
let tab_id = tab.tab_id();
let spawner = self.spawner.borrow().as_ref().unwrap().clone();
thread::spawn(move || read_from_tab_pty(spawner, sender, tab_id, reader));
thread::spawn(move || read_from_tab_pty(executor, spawner, sender, tab_id, reader));
Ok(())
}
pub fn remove_tab(&self, tab_id: TabId) {
eprintln!("removing tab {}", tab_id);
self.tabs.borrow_mut().remove(&tab_id);
}
pub fn process_pty_event(&self, event: PtyEvent) -> Result<(), Error> {
match event {
PtyEvent::Data { tab_id, data } => {
@@ -134,7 +147,7 @@ impl Mux {
// The fact that we woke up is enough to trigger each
// window to check for termination
eprintln!("tab {} terminated", tab_id);
self.tabs.borrow_mut().remove(&tab_id);
self.remove_tab(tab_id);
}
}
Ok(())