add a timeout to flush_pending()
authorRobin Gareus <robin@gareus.org>
Mon, 25 Jul 2016 12:13:52 +0000 (14:13 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 25 Jul 2016 12:13:52 +0000 (14:13 +0200)
In some circumstances UI::flush_pending never returns, and all UI
interactive ends up being driven by
   while (gtk_events_pending()) { gtk_main_iteration(); }
This has various implications depending on the caller and usually results
in a crash at session-close or exit.

libs/gtkmm2ext/gtk_ui.cc
libs/gtkmm2ext/gtkmm2ext/gtk_ui.h

index c3e94c922eee2c3b5899afabc5b9eaac6d96ce8e..c96c31b3dec8b082e62cc16e7bec49d98e4381cc 100644 (file)
@@ -728,7 +728,7 @@ UI::popup_error (const string& text)
 }
 
 void
-UI::flush_pending ()
+UI::flush_pending (float timeout)
 {
        if (!caller_is_ui_thread()) {
                error << "non-UI threads cannot call UI::flush_pending()"
@@ -736,9 +736,15 @@ UI::flush_pending ()
                return;
        }
 
+       int64_t end = g_get_monotonic_time () + timeout * 1e6;
+
        gtk_main_iteration();
 
        while (gtk_events_pending()) {
+               if (timeout > 0 && end < g_get_monotonic_time ()) {
+                       cerr << "UI::flush_pending timed out after " << timeout << "s.\n";
+                       break;
+               }
                gtk_main_iteration();
        }
 }
index b9c80a34e09075455adcd782b19dd4211b4c9278..dbe1739ffc76cc599d5276f32e56134f4d02555f 100644 (file)
@@ -136,7 +136,7 @@ class LIBGTKMM2EXT_API UI : public AbstractUI<UIRequest>
 
        void set_state (Gtk::Widget *w, Gtk::StateType state);
        void popup_error (const std::string& text);
-       void flush_pending ();
+       void flush_pending (float timeout = 0);
        void toggle_errors ();
        void show_errors ();
        void dump_errors (std::ostream&);