[gnome-builder] buffer: use GWeakNotify to handle context changes



commit 229aa41082e13d81fd4a3b32590619ea4a525e39
Author: Christian Hergert <christian hergert me>
Date:   Tue Apr 28 18:03:54 2015 -0700

    buffer: use GWeakNotify to handle context changes
    
    We need to drop our reclamation timeout when we lose our context. This
    can happen if we immediately close the workbench after releasing a buffer
    and another workbench is open.

 libide/ide-buffer.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index bb20c74..910fa13 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -157,6 +157,33 @@ ide_buffer_get_iter_at_location (IdeBuffer         *self,
 }
 
 static void
+ide_buffer_release_context (gpointer  data,
+                            GObject  *where_the_object_was)
+{
+  IdeBuffer *self = data;
+  IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_BUFFER (self));
+
+  priv->context = NULL;
+
+  /*
+   * If the context was just lost, we handled reclamation in the buffer
+   * manager while shutting down. We can safely drop our reclamation_handler
+   * since it can no longer be run anyway.
+   */
+  if (priv->reclamation_handler != 0)
+    {
+      g_source_remove (priv->reclamation_handler);
+      priv->reclamation_handler = 0;
+    }
+
+  IDE_EXIT;
+}
+
+static void
 ide_buffer_set_context (IdeBuffer  *self,
                         IdeContext *context)
 {
@@ -166,7 +193,11 @@ ide_buffer_set_context (IdeBuffer  *self,
   g_return_if_fail (IDE_IS_CONTEXT (context));
   g_return_if_fail (priv->context == NULL);
 
-  ide_set_weak_pointer (&priv->context, context);
+  priv->context = context;
+
+  g_object_weak_ref (G_OBJECT (context),
+                     ide_buffer_release_context,
+                     self);
 }
 
 static void
@@ -1898,6 +1929,9 @@ ide_buffer_hold (IdeBuffer *self)
 
   priv->hold_count++;
 
+  if (priv->context == NULL)
+    return;
+
   if (priv->reclamation_handler != 0)
     {
       g_source_remove (priv->reclamation_handler);
@@ -1915,6 +1949,9 @@ ide_buffer_release (IdeBuffer *self)
 
   priv->hold_count--;
 
+  if (priv->context == NULL)
+    return;
+
   /*
    * If our hold count has reached zero, then queue the buffer for
    * reclamation by the buffer manager after a grace period has elapsed.


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