[glib/gobject-performance] Make type_data_unref_U not take locks in the common case
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/gobject-performance] Make type_data_unref_U not take locks in the common case
- Date: Thu, 24 Sep 2009 11:30:45 +0000 (UTC)
commit 38bf9d270b78cb811ba973702e942f8f02e8e04a
Author: Edward Hervey <bilboed bilboed com>
Date: Thu Sep 24 11:45:13 2009 +0200
Make type_data_unref_U not take locks in the common case
https://bugzilla.gnome.org/show_bug.cgi?id=585375
gobject/gtype.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index e83fa9d..6861a9d 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -2344,11 +2344,12 @@ static inline void
type_data_unref_U (TypeNode *node,
gboolean uncached)
{
- G_WRITE_LOCK (&type_rw_lock);
- g_assert (node->data && NODE_REFCOUNT (node) > 0);
- if (NODE_REFCOUNT (node) > 1)
- g_atomic_int_add ((int *) &node->ref_count, -1);
- else
+ guint current;
+
+ do {
+ current = NODE_REFCOUNT (node);
+
+ if (current <= 1)
{
if (!node->plugin)
{
@@ -2356,13 +2357,17 @@ type_data_unref_U (TypeNode *node,
NODE_NAME (node));
return;
}
- G_WRITE_UNLOCK (&type_rw_lock);
+
+ g_assert (current > 0);
+
g_static_rec_mutex_lock (&class_init_rec_mutex); /* required locking order: 1) class_init_rec_mutex, 2) type_rw_lock */
G_WRITE_LOCK (&type_rw_lock);
type_data_last_unref_Wm (node, uncached);
+ G_WRITE_UNLOCK (&type_rw_lock);
g_static_rec_mutex_unlock (&class_init_rec_mutex);
+ return;
}
- G_WRITE_UNLOCK (&type_rw_lock);
+ } while (!g_atomic_int_compare_and_exchange ((int *) &node->ref_count, current, current - 1));
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]