[geary/wip/555-sync-cancelled: 2/2] Decouple account processor closing and its op cancellables



commit 97ff689bd166f650e1569d639d1fece696302431
Author: Michael Gratton <mike vee net>
Date:   Fri Sep 6 22:15:07 2019 +1000

    Decouple account processor closing and its op cancellables
    
    By using a single cancellable for both managing the running state of
    the AccountProcessor and its operations, if an op cancelled its own
    cancellable, it would also stop the processor (and if it didn't, also
    pre-cancel andy future ops).
    
    Fix this by decopling processor running state from the operation
    cancellables, and use a new cancellable for each operation.

 .../imap-engine/imap-engine-account-processor.vala  | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/imap-engine/imap-engine-account-processor.vala 
b/src/engine/imap-engine/imap-engine-account-processor.vala
index 9729032f..49752361 100644
--- a/src/engine/imap-engine/imap-engine-account-processor.vala
+++ b/src/engine/imap-engine/imap-engine-account-processor.vala
@@ -41,17 +41,19 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
 
     private string id;
 
+    private bool is_running;
+
     private Nonblocking.Queue<AccountOperation> queue =
         new Nonblocking.Queue<AccountOperation>.fifo(op_equal);
 
     private AccountOperation? current_op = null;
-
-    private Cancellable cancellable = new Cancellable();
+    private GLib.Cancellable? op_cancellable = null;
 
 
     public AccountProcessor(string id) {
         this.id = id;
         this.queue.allow_duplicates = false;
+        this.is_running = true;
         this.run.begin();
     }
 
@@ -62,15 +64,21 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
     }
 
     public void stop() {
-        this.cancellable.cancel();
+        this.is_running = false;
+        if (this.op_cancellable != null) {
+            this.op_cancellable.cancel();
+            this.op_cancellable = null;
+        }
         this.queue.clear();
     }
 
     private async void run() {
-        while (!this.cancellable.is_cancelled()) {
+        while (this.is_running) {
+            this.op_cancellable = new GLib.Cancellable();
+
             AccountOperation? op = null;
             try {
-                op = yield this.queue.receive(this.cancellable);
+                op = yield this.queue.receive(this.op_cancellable);
             } catch (Error err) {
                 // we've been cancelled, so bail out
                 return;
@@ -84,7 +92,7 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
                 int network_errors = 0;
                 while (op_error == null) {
                     try {
-                        yield op.execute(this.cancellable);
+                        yield op.execute(this.op_cancellable);
                         op.succeeded();
                         break;
                     } catch (ImapError err) {
@@ -109,6 +117,7 @@ internal class Geary.ImapEngine.AccountProcessor : Geary.BaseObject {
                 op.completed();
 
                 this.current_op = null;
+                this.op_cancellable = null;
             }
         }
     }


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