[glib: 1/4] gvariant-core: Use gatomicrefcount for GVariant reference count
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/4] gvariant-core: Use gatomicrefcount for GVariant reference count
- Date: Thu, 8 Nov 2018 14:22:21 +0000 (UTC)
commit 6d108587a4896357be3ca42a43d22c825af62e91
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date: Fri Nov 2 00:00:00 2018 +0000
gvariant-core: Use gatomicrefcount for GVariant reference count
glib/gvariant-core.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
---
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index 815bdf9e0..8e4ff057a 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -28,6 +28,7 @@
#include <glib/gbytes.h>
#include <glib/gslice.h>
#include <glib/gmem.h>
+#include <glib/grefcount.h>
#include <string.h>
@@ -74,7 +75,7 @@ struct _GVariant
} contents;
gint state;
- gint ref_count;
+ gatomicrefcount ref_count;
gsize depth;
};
@@ -488,7 +489,7 @@ g_variant_alloc (const GVariantType *type,
(trusted ? STATE_TRUSTED : 0) |
STATE_FLOATING;
value->size = (gssize) -1;
- value->ref_count = 1;
+ g_atomic_ref_count_init (&value->ref_count);
value->depth = 0;
return value;
@@ -632,9 +633,8 @@ void
g_variant_unref (GVariant *value)
{
g_return_if_fail (value != NULL);
- g_return_if_fail (value->ref_count > 0);
- if (g_atomic_int_dec_and_test (&value->ref_count))
+ if (g_atomic_ref_count_dec (&value->ref_count))
{
if G_UNLIKELY (value->state & STATE_LOCKED)
g_critical ("attempting to free a locked GVariant instance. "
@@ -668,9 +668,8 @@ GVariant *
g_variant_ref (GVariant *value)
{
g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->ref_count > 0, NULL);
- g_atomic_int_inc (&value->ref_count);
+ g_atomic_ref_count_inc (&value->ref_count);
return value;
}
@@ -710,7 +709,7 @@ GVariant *
g_variant_ref_sink (GVariant *value)
{
g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->ref_count > 0, NULL);
+ g_return_val_if_fail (!g_atomic_ref_count_compare (&value->ref_count, 0), NULL);
g_variant_lock (value);
@@ -767,7 +766,7 @@ GVariant *
g_variant_take_ref (GVariant *value)
{
g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->ref_count > 0, NULL);
+ g_return_val_if_fail (!g_atomic_ref_count_compare (&value->ref_count, 0), NULL);
g_atomic_int_and (&value->state, ~STATE_FLOATING);
@@ -1043,7 +1042,7 @@ g_variant_get_child_value (GVariant *value,
child->state = (value->state & STATE_TRUSTED) |
STATE_SERIALISED;
child->size = s_child.size;
- child->ref_count = 1;
+ g_atomic_ref_count_init (&child->ref_count);
child->depth = value->depth + 1;
child->contents.serialised.bytes =
g_bytes_ref (value->contents.serialised.bytes);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]