add a timeout to flush_pending()
[ardour.git] / libs / gtkmm2ext / gtk_ui.cc
index e220a37a280f94eb3f23bb66b631fc822843db45..c96c31b3dec8b082e62cc16e7bec49d98e4381cc 100644 (file)
@@ -46,7 +46,7 @@
 #include "gtkmm2ext/actions.h"
 #include "gtkmm2ext/gui_thread.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace Gtkmm2ext;
 using namespace Gtk;
@@ -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();
        }
 }