Fix idle add problem

This commit is contained in:
daa84 2016-03-28 17:14:10 +03:00
parent fae82271d1
commit 0b4504e6d7
3 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,5 @@
extern crate gtk;
extern crate glib;
extern crate cairo;
extern crate neovim_lib;
extern crate rmp;

View File

@ -6,7 +6,7 @@ use ui_mutex::UiMutex;
use rmp::Value;
use rmp::value::Integer;
use ui::Ui;
use gtk;
use glib;
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)
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) {
println!("Error call function: {}", msg);
}
gtk::Continue(false)
glib::Continue(false)
});
}

View File

@ -20,8 +20,9 @@ impl<T> UiMutex<T> {
}
pub fn borrow_mut(&self) -> RefMut<T> {
if thread::current().name().map(|v| v.to_owned()) != self.main_thread_name {
panic!("Can access value only from main thread");
let current_thread_name = thread::current().name().map(|v| v.to_owned());
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()