[glib/wip/gproperty-2: 176/178] gobject: Add quark-based locking



commit 3fcb57fadf4bee78d0370d90f31e6439e4fa5bfa
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri May 3 17:16:33 2013 -0700

    gobject: Add quark-based locking

 gobject/gobject.c       |   29 +++++++++++++++++++++++++++++
 gobject/gproperty.c     |   21 ++++-----------------
 gobject/gtype-private.h |    5 +++++
 3 files changed, 38 insertions(+), 17 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 2724075..991cbeb 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -4387,3 +4387,32 @@ g_weak_ref_set (GWeakRef *weak_ref,
 
   g_rw_lock_writer_unlock (&weak_locations_lock);
 }
+
+void
+_g_object_lock (gpointer object,
+                GQuark   lock_id)
+{
+  gint *bit_lock_p;
+
+  bit_lock_p = g_object_get_qdata (object, lock_id);
+  if (bit_lock_p == NULL)
+    {
+      bit_lock_p = g_new (gint, 1);
+      g_object_set_qdata_full (object, lock_id, bit_lock_p, g_free);
+    }
+
+  g_bit_lock (bit_lock_p, 0);
+}
+
+void
+_g_object_unlock (gpointer object,
+                  GQuark   lock_id)
+{
+  gint *bit_lock_p;
+
+  bit_lock_p = g_object_get_qdata (object, lock_id);
+  if (bit_lock_p == NULL)
+    return;
+
+  g_bit_unlock (bit_lock_p, 0);
+}
diff --git a/gobject/gproperty.c b/gobject/gproperty.c
index 3cba304..4d52596 100644
--- a/gobject/gproperty.c
+++ b/gobject/gproperty.c
@@ -334,6 +334,7 @@
 #include "gvaluecollector.h"
 #include "gparam.h"
 #include "gtype.h"
+#include "gtype-private.h"
 #include "gvalue.h"
 #include "gvaluetypes.h"
 
@@ -689,32 +690,18 @@ static void
 g_property_default_lock (GProperty *property,
                          gpointer   gobject)
 {
-  gpointer bit_lock_p;
-
   g_property_ensure_prop_id (property);
 
-  bit_lock_p = g_object_get_qdata (gobject, property->prop_id);
-  if (bit_lock_p == NULL)
-    {
-      bit_lock_p = g_new0 (gint, 1);
-      g_object_set_qdata_full (gobject, property->prop_id, bit_lock_p, g_free);
-    }
-
-  g_bit_lock (bit_lock_p, 0);
+  _g_object_lock (gobject, property->prop_id);
 }
 
 static void
 g_property_default_unlock (GProperty *property,
                            gpointer   gobject)
 {
-  gpointer bit_lock_p;
-
-  bit_lock_p = g_object_get_qdata (gobject, property->prop_id);
-  if (bit_lock_p == NULL)
-    return;
+  g_property_ensure_prop_id (property);
 
-  g_bit_unlock (bit_lock_p, 0);
-  g_object_set_qdata (gobject, property->prop_id, NULL);
+  _g_object_unlock (gobject, property->prop_id);
 }
 
 static inline void
diff --git a/gobject/gtype-private.h b/gobject/gtype-private.h
index d9e31e4..7df904b 100644
--- a/gobject/gtype-private.h
+++ b/gobject/gtype-private.h
@@ -74,6 +74,11 @@ void        _g_closure_invoke_va (GClosure       *closure,
 
 gboolean    g_type_is_in_init    (GType type);
 
+void    _g_object_lock          (gpointer object,
+                                 GQuark   lock_id);
+void    _g_object_unlock        (gpointer object,
+                                 GQuark   lock_id);
+
 G_END_DECLS
 
 #endif /* __G_TYPE_PRIVATE_H__ */


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