[json-glib] Use the new atomic functions for refcounting



commit 74bb5d61a737cceffd04c8d9ae8d5db390eda5a2
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Jun 3 11:46:05 2011 +0100

    Use the new atomic functions for refcounting
    
    The newly added g_atomic_int_dec_and_test() simplified the logic for
    unreffing Object and Array.

 json-glib/json-array.c  |    9 ++-------
 json-glib/json-object.c |    9 ++-------
 2 files changed, 4 insertions(+), 14 deletions(-)
---
diff --git a/json-glib/json-array.c b/json-glib/json-array.c
index e81e846..3a21d9e 100644
--- a/json-glib/json-array.c
+++ b/json-glib/json-array.c
@@ -102,7 +102,7 @@ json_array_ref (JsonArray *array)
   g_return_val_if_fail (array != NULL, NULL);
   g_return_val_if_fail (array->ref_count > 0, NULL);
 
-  g_atomic_int_exchange_and_add (&array->ref_count, 1);
+  g_atomic_int_add (&array->ref_count, 1);
 
   return array;
 }
@@ -118,15 +118,10 @@ json_array_ref (JsonArray *array)
 void
 json_array_unref (JsonArray *array)
 {
-  gint old_ref;
-
   g_return_if_fail (array != NULL);
   g_return_if_fail (array->ref_count > 0);
 
-  old_ref = g_atomic_int_get (&array->ref_count);
-  if (old_ref > 1)
-    g_atomic_int_compare_and_exchange (&array->ref_count, old_ref, old_ref - 1);
-  else
+  if (g_atomic_int_dec_and_test (&array->ref_count))
     {
       guint i;
 
diff --git a/json-glib/json-object.c b/json-glib/json-object.c
index 438366b..e8e88fb 100644
--- a/json-glib/json-object.c
+++ b/json-glib/json-object.c
@@ -89,7 +89,7 @@ json_object_ref (JsonObject *object)
   g_return_val_if_fail (object != NULL, NULL);
   g_return_val_if_fail (object->ref_count > 0, NULL);
 
-  g_atomic_int_exchange_and_add (&object->ref_count, 1);
+  g_atomic_int_add (&object->ref_count, 1);
 
   return object;
 }
@@ -105,15 +105,10 @@ json_object_ref (JsonObject *object)
 void
 json_object_unref (JsonObject *object)
 {
-  gint old_ref;
-
   g_return_if_fail (object != NULL);
   g_return_if_fail (object->ref_count > 0);
 
-  old_ref = g_atomic_int_get (&object->ref_count);
-  if (old_ref > 1)
-    g_atomic_int_compare_and_exchange (&object->ref_count, old_ref, old_ref - 1);
-  else
+  if (g_atomic_int_dec_and_test (&object->ref_count))
     {
       g_list_free (object->members_ordered);
       g_hash_table_destroy (object->members);



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