Revert my revision 6996, which was wrong. Sources need to stay around in the session...
[ardour.git] / libs / pbd / base_ui.cc
index 259a51d9549b806e16da2250c488c778e05189fd..ce7018a005293014c95b937468ef853c118deeed 100644 (file)
@@ -25,6 +25,7 @@
 #include <cstring>
 
 #include "pbd/base_ui.h"
+#include "pbd/pthread_utils.h"
 #include "pbd/error.h"
 #include "pbd/compose.h"
 #include "pbd/failed_constructor.h"
@@ -37,6 +38,7 @@ using namespace Glib;
        
 uint64_t BaseUI::rt_bit = 1;
 BaseUI::RequestType BaseUI::CallSlot = BaseUI::new_request_type();
+BaseUI::RequestType BaseUI::Quit = BaseUI::new_request_type();
 
 BaseUI::BaseUI (const string& str)
        : run_loop_thread (0)
@@ -69,6 +71,7 @@ BaseUI::new_request_type ()
 void
 BaseUI::main_thread ()
 {
+       set_event_loop_for_thread (this);
        thread_init ();
        _main_loop->run ();
 }
@@ -77,19 +80,24 @@ void
 BaseUI::run ()
 {
        /* to be called by UI's that need/want their own distinct, self-created event loop thread.
-          Derived classes should have set up a handler for IO on request_channel.ios()
        */
 
        _main_loop = MainLoop::create (MainContext::create());
        request_channel.ios()->attach (_main_loop->get_context());
+
+       /* glibmm hack - drop the refptr to the IOSource now before it can hurt */
+       request_channel.drop_ios ();
+
        run_loop_thread = Thread::create (mem_fun (*this, &BaseUI::main_thread), true);
 }
 
 void
 BaseUI::quit ()
 {
-       _main_loop->quit ();
-       run_loop_thread->join ();
+       if (_main_loop->is_running()) {
+               _main_loop->quit ();
+               run_loop_thread->join ();
+       }
 }
 
 bool