diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-06-03 11:46:05 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-06-03 11:46:05 +0100 |
commit | 74bb5d61a737cceffd04c8d9ae8d5db390eda5a2 (patch) | |
tree | bfbdb7efffd574ffd555fdbebc8fc5cbaa45c8da /json-glib/json-object.c | |
parent | 4f83868e3a18adac809aff111c5df5ff7af8fedf (diff) | |
download | json-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.c | 9 |
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); |