mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 08:16:24 +01:00
gvariant-core: Use gatomicrefcount for GVariant reference count
This commit is contained in:
parent
a3ad5a2ce0
commit
6d108587a4
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user