From 0b4504e6d76e61ffb1f916515d9787dc469cca2e Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 28 Mar 2016 17:14:10 +0300 Subject: [PATCH] Fix idle add problem --- src/main.rs | 1 + src/nvim.rs | 8 ++++---- src/ui_mutex.rs | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23500de..b6e14b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate gtk; +extern crate glib; extern crate cairo; extern crate neovim_lib; extern crate rmp; diff --git a/src/nvim.rs b/src/nvim.rs index b6cca69..afce458 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -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>; @@ -88,12 +88,12 @@ fn call(ui: &SharedUi, method: &str, args: Vec) { } fn safe_call(mutex: SharedUi, cb: F) - where F: Fn(&UiMutex) -> result::Result<(), String> + 'static + where F: Fn(&UiMutex) -> 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) }); } diff --git a/src/ui_mutex.rs b/src/ui_mutex.rs index 70d7702..6d423b3 100644 --- a/src/ui_mutex.rs +++ b/src/ui_mutex.rs @@ -20,8 +20,9 @@ impl UiMutex { } pub fn borrow_mut(&self) -> RefMut { - 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()