From 74bb5d61a737cceffd04c8d9ae8d5db390eda5a2 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 3 Jun 2011 11:46:05 +0100 Subject: 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-object.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'json-glib/json-object.c') 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); -- cgit v1.2.1