[gnote] Handle exception in main_context_call and spurious wakeup



commit d4c4e9c0085e2fc66519b5755310989a9ad29487
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Feb 1 22:19:20 2020 +0200

    Handle exception in main_context_call and spurious wakeup

 src/utils.cpp | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/src/utils.cpp b/src/utils.cpp
index 0556e987..3a086d7e 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -96,16 +96,6 @@ namespace gnote {
         delete slot;
         return FALSE;
       }
-
-      void main_context_call_func(const sigc::slot<void> & slot,
-                                  Glib::Threads::Cond * cond,
-                                  Glib::Threads::Mutex * mutex)
-      {
-        mutex->lock();
-        slot();
-        cond->signal();
-        mutex->unlock();
-      }
    }
 
 
@@ -258,13 +248,29 @@ namespace gnote {
     {
       Glib::Threads::Mutex mutex;
       Glib::Threads::Cond cond;
+      bool executed = false;
+      std::exception_ptr ex;
 
       mutex.lock();
-      main_context_invoke([slot, &cond, &mutex]() {
-        main_context_call_func(slot, &cond, &mutex);
+      main_context_invoke([slot, &cond, &mutex, &executed, &ex]() {
+        try {
+          mutex.lock();
+          slot();
+        }
+        catch(...) {
+          ex = std::current_exception();
+        }
+        executed = true;
+        cond.signal();
+        mutex.unlock();
       });
-      cond.wait(mutex);
+      while(!executed) {
+        cond.wait(mutex);
+      }
       mutex.unlock();
+      if(ex) {
+        std::rethrow_exception(ex);
+      }
     }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]