Try to directly call UI callbacks if we're already in the UI thread; call wake_ui...
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Oct 2012 01:03:13 +0000 (02:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 25 Oct 2012 01:03:13 +0000 (02:03 +0100)
src/lib/ui_signaller.h

index 0797d911e7123198f02f4c0fd3c061ae4dc3d9b4..9de1b736ddf6246b4e7ac7b37598d50746bbe2f6 100644 (file)
 
 #include <boost/bind.hpp>
 #include <boost/asio.hpp>
+#include <boost/thread.hpp>
 
 class UISignaller
 {
 public:
+       /** Create a UISignaller.  Must be called from the UI thread */
        UISignaller ()
                : _work (_service)
-       {}
+       {
+               _ui_thread = boost::this_thread::get_id ();
+       }
        
        template <typename T>
        void emit (T f) {
-               _service.post (f);
+               if (boost::this_thread::get_id() == _ui_thread) {
+                       f ();
+               } else {
+                       _service.post (f);
+                       wake_ui ();
+               }
        }
 
        void ui_idle () {
@@ -44,6 +53,7 @@ public:
 private:
        boost::asio::io_service _service;
        boost::asio::io_service::work _work;
+       boost::thread::id _ui_thread;
 };
 
 extern UISignaller* ui_signaller;