added floating reference count. g_object_is_floating():
authorTim Janik <timj@imendio.com>
Wed, 23 Nov 2005 17:54:41 +0000 (17:54 +0000)
committerTim Janik <timj@src.gnome.org>
Wed, 23 Nov 2005 17:54:41 +0000 (17:54 +0000)
Wed Nov 23 18:01:46 2005  Tim Janik  <timj@imendio.com>

        * gobject.[hc]: added floating reference count.
        g_object_is_floating():
        g_object_ref_sink(): new functions to deal with floating references.
        g_object_force_floating(): new funciton for object implementations
        to set the floating flag.

        * gobject.c (g_object_init): make objects initially floating.

Wed Nov 23 17:58:13 2005  Tim Janik  <timj@gtk.org>

        * gparam.[hc]: added g_param_spec_ref_sink().

gobject/ChangeLog
gobject/gobject.c
gobject/gobject.h
gobject/gobject.symbols
gobject/gparam.c
gobject/gparam.h

index ab60715..bcbd710 100644 (file)
@@ -1,3 +1,17 @@
+Wed Nov 23 18:01:46 2005  Tim Janik  <timj@imendio.com>
+
+       * gobject.[hc]: added floating reference count.
+       g_object_is_floating():
+       g_object_ref_sink(): new functions to deal with floating references.
+       g_object_force_floating(): new funciton for object implementations
+       to set the floating flag.
+
+       * gobject.c (g_object_init): make objects initially floating.
+
+Wed Nov 23 17:58:13 2005  Tim Janik  <timj@gtk.org>
+
+       * gparam.[hc]: added g_param_spec_ref_sink().
+
 Wed Nov 23 13:36:02 2005  Tim Janik  <timj@gtk.org>
 
        * gboxed.[hc]: minor cleanups, implemented G_TYPE_HASH_TABLE.
index de409a8..85ed73d 100644 (file)
@@ -42,7 +42,8 @@
 
 #define OBJECT_HAS_TOGGLE_REF_FLAG 0x1
 #define OBJECT_HAS_TOGGLE_REF(object) \
-    ((G_DATALIST_GET_FLAGS(&(object)->qdata) & OBJECT_HAS_TOGGLE_REF_FLAG) != 0)
+    ((G_DATALIST_GET_FLAGS (&(object)->qdata) & OBJECT_HAS_TOGGLE_REF_FLAG) != 0)
+#define OBJECT_FLOATING_FLAG 0x2
 
 
 /* --- signals --- */
@@ -472,6 +473,7 @@ g_object_init (GObject *object)
 {
   object->ref_count = 1;
   g_datalist_init (&object->qdata);
+  g_object_force_floating (object);
   
   /* freeze object's notification queue, g_object_newv() preserves pairedness */
   g_object_notify_queue_freeze (object, &property_notify_context);
@@ -1518,6 +1520,47 @@ g_object_remove_weak_pointer (GObject  *object,
                        weak_pointer_location);
 }
 
+gboolean
+g_object_is_floating (gpointer _object)
+{
+  GObject *object = _object;
+  g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
+  return ((gsize) g_atomic_pointer_get (&object->qdata) & OBJECT_FLOATING_FLAG) != 0;
+}
+
+gpointer
+g_object_ref_sink (gpointer _object)
+{
+  GObject *object = _object;
+  gpointer oldvalue;
+  g_return_val_if_fail (G_IS_OBJECT (object), object);
+  g_return_val_if_fail (object->ref_count >= 1, object);
+  g_object_ref (object);
+  do
+    {
+      oldvalue = g_atomic_pointer_get (&object->qdata);
+    }
+  while (!g_atomic_pointer_compare_and_exchange ((void**) &object->qdata, oldvalue,
+                                                 (gpointer) ((gsize) oldvalue & ~(gsize) OBJECT_FLOATING_FLAG)));
+  if ((gsize) oldvalue & OBJECT_FLOATING_FLAG)
+    g_object_unref (object);
+  return object;
+}
+
+void
+g_object_force_floating (GObject *object)
+{
+  gpointer oldvalue;
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (object->ref_count >= 1);
+  do
+    {
+      oldvalue = g_atomic_pointer_get (&object->qdata);
+    }
+  while (!g_atomic_pointer_compare_and_exchange ((void**) &object->qdata, oldvalue,
+                                                 (gpointer) ((gsize) oldvalue | OBJECT_FLOATING_FLAG)));
+}
+
 typedef struct {
   GObject *object;
   guint n_toggle_refs;
index da2c47c..bb684f4 100644 (file)
@@ -166,6 +166,8 @@ void        g_object_freeze_notify            (GObject        *object);
 void        g_object_notify                   (GObject        *object,
                                               const gchar    *property_name);
 void        g_object_thaw_notify              (GObject        *object);
+gboolean    g_object_is_floating             (gpointer        object);
+gpointer    g_object_ref_sink                (gpointer        object);
 gpointer    g_object_ref                      (gpointer        object);
 void        g_object_unref                    (gpointer        object);
 void       g_object_weak_ref                 (GObject        *object,
@@ -232,6 +234,7 @@ gulong          g_signal_connect_object           (gpointer        instance,
 
 
 /*< protected >*/
+void        g_object_force_floating           (GObject        *object);
 void        g_object_run_dispose             (GObject        *object);
 
 
index 86c5707..d1a5476 100644 (file)
@@ -131,7 +131,11 @@ g_object_new
 g_object_newv
 g_object_new_valist
 g_object_notify
+g_object_is_floating
+g_object_ref_sink
+g_object_force_floating
 g_object_ref
+g_object_unref
 g_object_remove_weak_pointer
 g_object_run_dispose
 g_object_set G_GNUC_NULL_TERMINATED
@@ -144,7 +148,6 @@ g_object_set_valist
 g_object_steal_data
 g_object_steal_qdata
 g_object_thaw_notify
-g_object_unref
 g_object_watch_closure
 g_object_weak_ref
 g_object_weak_unref
@@ -196,6 +199,7 @@ g_param_spec_get_redirect_target
 g_param_spec_internal
 g_param_type_register_static
 g_param_spec_ref
+g_param_spec_ref_sink
 g_param_spec_unref
 g_param_spec_sink
 g_param_spec_steal_qdata
index 454e344..327e65e 100644 (file)
@@ -201,6 +201,17 @@ g_param_spec_sink (GParamSpec *pspec)
     g_param_spec_unref (pspec);
 }
 
+GParamSpec*
+g_param_spec_ref_sink (GParamSpec *pspec)
+{
+  g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
+  g_return_val_if_fail (pspec->ref_count > 0, NULL);
+
+  g_param_spec_ref (pspec);
+  g_param_spec_sink (pspec);
+  return pspec;
+}
+
 G_CONST_RETURN gchar*
 g_param_spec_get_name (GParamSpec *pspec)
 {
index 38811dd..8676300 100644 (file)
@@ -117,6 +117,7 @@ struct _GParameter /* auxillary structure for _setv() variants */
 GParamSpec*    g_param_spec_ref                (GParamSpec    *pspec);
 void           g_param_spec_unref              (GParamSpec    *pspec);
 void           g_param_spec_sink               (GParamSpec    *pspec);
+GParamSpec*    g_param_spec_ref_sink           (GParamSpec    *pspec);
 gpointer        g_param_spec_get_qdata         (GParamSpec    *pspec,
                                                 GQuark         quark);
 void            g_param_spec_set_qdata         (GParamSpec    *pspec,