From 95d2479ea6ff65fd9c22c5ace119d9df1b0b8dc4 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 26 Mar 2019 08:48:01 -0700 Subject: [PATCH] gui_executor is intended to be obtainable from any thread --- src/frontend/mod.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 4e8fc2116..fe7957b47 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -3,11 +3,11 @@ use crate::font::FontConfiguration; use crate::mux::tab::Tab; use crate::mux::Mux; use failure::{format_err, Error}; +use lazy_static::lazy_static; use promise::Executor; use serde_derive::*; -use std::cell::RefCell; use std::rc::Rc; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; pub mod glium; pub mod guicommon; @@ -35,18 +35,16 @@ impl Default for FrontEndSelection { } } -thread_local! { - static EXECUTOR: RefCell>> = RefCell::new(None); +lazy_static! { + static ref EXECUTOR: Mutex>> = Mutex::new(None); } pub fn gui_executor() -> Option> { - let mut res = None; - EXECUTOR.with(|exec| { - if let Some(exec) = &*exec.borrow() { - res = Some(exec.clone_executor()); - } - }); - res + let locked = EXECUTOR.lock().unwrap(); + match locked.as_ref() { + Some(exec) => Some(exec.clone_executor()), + None => None, + } } impl FrontEndSelection { @@ -61,9 +59,7 @@ impl FrontEndSelection { FrontEndSelection::Null => muxserver::MuxServerFrontEnd::new_null(mux), }?; - EXECUTOR.with(|exec| { - *exec.borrow_mut() = Some(front_end.gui_executor()); - }); + EXECUTOR.lock().unwrap().replace(front_end.gui_executor()); Ok(front_end) }