summaryrefslogtreecommitdiff
path: root/json-glib/json-object.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2011-06-03 11:46:05 +0100
committerEmmanuele Bassi <ebassi@linux.intel.com>2011-06-03 11:46:05 +0100
commit74bb5d61a737cceffd04c8d9ae8d5db390eda5a2 (patch)
treebfbdb7efffd574ffd555fdbebc8fc5cbaa45c8da /json-glib/json-object.c
parent4f83868e3a18adac809aff111c5df5ff7af8fedf (diff)
downloadjson-glib-74bb5d61a737cceffd04c8d9ae8d5db390eda5a2.tar.gz
Use the new atomic functions for refcounting
The newly added g_atomic_int_dec_and_test() simplified the logic for unreffing Object and Array.
Diffstat (limited to 'json-glib/json-object.c')
-rw-r--r--json-glib/json-object.c9
1 files changed, 2 insertions, 7 deletions
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);