[geary: 1/3] Correct locking in create_controler



commit 42dfba9b007c9c76a4101e9f22997b0e4d62c68f
Author: Jiří Černý <ji cerny gmail com>
Date:   Tue May 21 15:53:31 2019 +0200

    Correct locking in create_controler
    
    Replace lock() which works only between threads, by geary internal
    mutex, which works between async functions.

 src/client/application/geary-application.vala | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index bd413d3e..64b616f1 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -694,6 +694,8 @@ public class GearyApplication : Gtk.Application {
         this.controller.main_window.present();
     }
 
+    private Geary.Nonblocking.Mutex controler_mutex = new Geary.Nonblocking.Mutex();
+
     // Opens the controller
     private async void create_controller() {
         // Manually keep the main loop around for the duration of this
@@ -701,7 +703,8 @@ public class GearyApplication : Gtk.Application {
         // hit the yield below, before we create the main window.
         hold();
 
-        lock (this.controller) {
+        try {
+            int mutex_token = yield controler_mutex.claim_async();
             if (this.controller == null) {
                 message(
                     "%s %s (%s) prefix=%s exec_dir=%s is_installed=%s",
@@ -717,6 +720,10 @@ public class GearyApplication : Gtk.Application {
                     this, this.controller_cancellable
                 );
             }
+
+            controler_mutex.release(ref mutex_token);
+        } catch (Error err) {
+            debug("Error creating controller: %s", err.message);
         }
 
         release();
@@ -727,11 +734,15 @@ public class GearyApplication : Gtk.Application {
         // see create_controller() for reasoning hold/release is used
         hold();
 
-        lock (this.controller) {
+        try {
+            int mutex_token = yield controler_mutex.claim_async();
             if (this.controller != null) {
                 yield this.controller.close_async();
                 this.controller = null;
             }
+            controler_mutex.release(ref mutex_token);
+        } catch (Error err) {
+            debug("Error creating controller: %s", err.message);
         }
 
         release();


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