[ostree] libostree: Add _finish() API to async progress



commit f040c02048978945ab82d31ced7c7db565647413
Author: Colin Walters <walters verbum org>
Date:   Tue Apr 29 08:54:39 2014 -0400

    libostree: Add _finish() API to async progress
    
    Since OstreeAsyncProgress queues to the mainloop, we might "lose" the
    last message.  Give callers a way to force a flush.

 src/libostree/ostree-async-progress.c   |   44 ++++++++++++++++++++++++++++--
 src/libostree/ostree-async-progress.h   |    2 +
 src/libostree/ostree-sysroot-upgrader.c |    3 ++
 src/ostree/ot-builtin-pull.c            |    3 ++
 4 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/src/libostree/ostree-async-progress.c b/src/libostree/ostree-async-progress.c
index fa7e60b..96257f4 100644
--- a/src/libostree/ostree-async-progress.c
+++ b/src/libostree/ostree-async-progress.c
@@ -63,6 +63,8 @@ struct OstreeAsyncProgress
   GHashTable *uint_values;
   GHashTable *uint64_values;
 
+  gboolean dead;
+
   char *status;
 };
 
@@ -184,9 +186,12 @@ ostree_async_progress_set_status (OstreeAsyncProgress       *self,
                                   const char                *status)
 {
   g_mutex_lock (&self->lock);
-  g_free (self->status);
-  self->status = g_strdup (status);
-  ensure_callback_locked (self);
+  if (!self->dead)
+    {
+      g_free (self->status);
+      self->status = g_strdup (status);
+      ensure_callback_locked (self);
+    }
   g_mutex_unlock (&self->lock);
 }
 
@@ -211,6 +216,9 @@ update_key (OstreeAsyncProgress   *self,
 
   g_mutex_lock (&self->lock);
 
+  if (self->dead)
+    goto out;
+
   if (g_hash_table_lookup_extended (hash, qkey, NULL, &orig_value))
     {
       if (orig_value == value)
@@ -270,3 +278,33 @@ ostree_async_progress_new_and_connect (void (*changed) (OstreeAsyncProgress *sel
   g_signal_connect (ret, "changed", G_CALLBACK (changed), user_data);
   return ret;
 }
+
+/**
+ * ostree_async_progress_finish:
+ * @self: Self
+ *
+ * Process any pending signals, ensuring the main context is cleared
+ * of sources used by this object.  Also ensures that no further
+ * events will be queued.
+ */
+void
+ostree_async_progress_finish (OstreeAsyncProgress *self)
+{
+  gboolean emit_changed = FALSE;
+
+  g_mutex_lock (&self->lock);
+  if (!self->dead)
+    {
+      self->dead = TRUE;
+      if (self->idle_source)
+        {
+          g_source_destroy (self->idle_source);
+          self->idle_source = NULL;
+          emit_changed = TRUE;
+        }
+    }
+  g_mutex_unlock (&self->lock);
+
+  if (emit_changed)
+    g_signal_emit (self, signals[CHANGED], 0);
+}
diff --git a/src/libostree/ostree-async-progress.h b/src/libostree/ostree-async-progress.h
index 71b2fba..6643013 100644
--- a/src/libostree/ostree-async-progress.h
+++ b/src/libostree/ostree-async-progress.h
@@ -64,5 +64,7 @@ void ostree_async_progress_set_uint64 (OstreeAsyncProgress       *self,
                                        const char                *key,
                                        guint64                    value);
 
+void ostree_async_progress_finish (OstreeAsyncProgress *self);
+
 G_END_DECLS
 
diff --git a/src/libostree/ostree-sysroot-upgrader.c b/src/libostree/ostree-sysroot-upgrader.c
index b62f8d4..61b6309 100644
--- a/src/libostree/ostree-sysroot-upgrader.c
+++ b/src/libostree/ostree-sysroot-upgrader.c
@@ -452,6 +452,9 @@ ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader  *self,
                              flags, progress,
                              cancellable, error))
         goto out;
+
+      if (progress)
+        ostree_async_progress_finish (progress);
     }
 
   if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &self->new_revision,
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index b7e4ca4..a29bbb7 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -89,6 +89,9 @@ ostree_builtin_pull (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
                          pullflags, progress, cancellable, error))
     goto out;
 
+  if (progress)
+    ostree_async_progress_finish (progress);
+
   ret = TRUE;
  out:
   if (console)


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