From ce17593a1a6c633415eccdbea8f76d2c0a7fd057 Mon Sep 17 00:00:00 2001 From: YPozdnyakov Date: Mon, 9 Feb 2015 16:40:06 +0200 Subject: [PATCH] [Summary]: safe behaviour of ProgressDialog::set_progress in case of calling this method NOT from gui thread. [Reviewed] Paul Davis --- gtk2_ardour/progress_dialog.cc | 32 +++++++++++++++----------------- gtk2_ardour/progress_dialog.h | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/gtk2_ardour/progress_dialog.cc b/gtk2_ardour/progress_dialog.cc index 8febaf2389..856b5534ad 100644 --- a/gtk2_ardour/progress_dialog.cc +++ b/gtk2_ardour/progress_dialog.cc @@ -127,18 +127,14 @@ ProgressDialog::show_pd () { WavesDialog::show (); /* Make sure the progress dialog is drawn */ - while (Glib::MainContext::get_default()->iteration (false)) { - /* do nothing */ - } + Glib::MainContext::get_default()->iteration (false); } void ProgressDialog::hide_pd () { - /* Make sure the progress dialog is drawn */ - while (Glib::MainContext::get_default()->iteration (false)) { - /* do nothing */ - } + Glib::MainContext::get_default()->iteration (false); + set_progress (0); WavesDialog::hide (); } @@ -164,19 +160,21 @@ ProgressDialog::set_cancel_button_sensitive (bool sensitive) void ProgressDialog::set_progress (float p) { - if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) { - // IF WE ARE NOT IN GUI THREAD - // we push method set_progress () to gui event loop - // from which it will be called afterwards - Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ProgressDialog::set_progress , this, p)); - return; - } + // IF WE ARE NOT IN GUI THREAD + // we push method set_progress () to gui event loop + // from which it will be called afterwards + Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&ProgressDialog::set_progress_in_gui_thread , this, p)); +} +void +ProgressDialog::set_progress_in_gui_thread (float p) +{ + // it's provided that this method can be called + // just from gui thread _progress_bar.set_fraction (p); - + // Make sure the progress widget gets updated - // it can be called just from gui-thread while (Glib::MainContext::get_default()->iteration (false)) { /* do nothing */ } -} \ No newline at end of file +} diff --git a/gtk2_ardour/progress_dialog.h b/gtk2_ardour/progress_dialog.h index d857707f24..df2c8e14cc 100644 --- a/gtk2_ardour/progress_dialog.h +++ b/gtk2_ardour/progress_dialog.h @@ -58,7 +58,7 @@ private: const std::string& top_message, const std::string& progress_message, const std::string& bottom_message); - + void set_progress_in_gui_thread (float); Gtk::Label& _top_label; Gtk::Label& _bottom_label; Gtk::ProgressBar& _progress_bar;