Fix idle add problem
This commit is contained in:
parent
fae82271d1
commit
0b4504e6d7
@ -1,4 +1,5 @@
|
|||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
|
extern crate glib;
|
||||||
extern crate cairo;
|
extern crate cairo;
|
||||||
extern crate neovim_lib;
|
extern crate neovim_lib;
|
||||||
extern crate rmp;
|
extern crate rmp;
|
||||||
|
@ -6,7 +6,7 @@ use ui_mutex::UiMutex;
|
|||||||
use rmp::Value;
|
use rmp::Value;
|
||||||
use rmp::value::Integer;
|
use rmp::value::Integer;
|
||||||
use ui::Ui;
|
use ui::Ui;
|
||||||
use gtk;
|
use glib;
|
||||||
|
|
||||||
pub type SharedUi = Arc<UiMutex<Ui>>;
|
pub type SharedUi = Arc<UiMutex<Ui>>;
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ fn call(ui: &SharedUi, method: &str, args: Vec<Value>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn safe_call<F>(mutex: SharedUi, cb: F)
|
fn safe_call<F>(mutex: SharedUi, cb: F)
|
||||||
where F: Fn(&UiMutex<Ui>) -> result::Result<(), String> + 'static
|
where F: Fn(&UiMutex<Ui>) -> result::Result<(), String> + 'static + Send
|
||||||
{
|
{
|
||||||
gtk::idle_add(move || {
|
glib::idle_add(move || {
|
||||||
if let Err(msg) = cb(&*mutex) {
|
if let Err(msg) = cb(&*mutex) {
|
||||||
println!("Error call function: {}", msg);
|
println!("Error call function: {}", msg);
|
||||||
}
|
}
|
||||||
gtk::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@ impl<T> UiMutex<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn borrow_mut(&self) -> RefMut<T> {
|
pub fn borrow_mut(&self) -> RefMut<T> {
|
||||||
if thread::current().name().map(|v| v.to_owned()) != self.main_thread_name {
|
let current_thread_name = thread::current().name().map(|v| v.to_owned());
|
||||||
panic!("Can access value only from main thread");
|
if current_thread_name != self.main_thread_name {
|
||||||
|
panic!("Can access value only from main thread, {:?}/{:?}", current_thread_name, self.main_thread_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.data.borrow_mut()
|
self.data.borrow_mut()
|
||||||
|
Loading…
Reference in New Issue
Block a user