mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 19:22:11 +01:00
Merge branch 'atomic-ref-count-cnd' into 'master'
Atomic reference count in GVariant, ContainerInfo and GDBus introspection See merge request GNOME/glib!452
This commit is contained in:
commit
0c6346c98f
@ -105,7 +105,7 @@ typedef struct
|
||||
GDBusNodeInfo *
|
||||
g_dbus_node_info_ref (GDBusNodeInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -125,7 +125,7 @@ g_dbus_node_info_ref (GDBusNodeInfo *info)
|
||||
GDBusInterfaceInfo *
|
||||
g_dbus_interface_info_ref (GDBusInterfaceInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -145,7 +145,7 @@ g_dbus_interface_info_ref (GDBusInterfaceInfo *info)
|
||||
GDBusMethodInfo *
|
||||
g_dbus_method_info_ref (GDBusMethodInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -165,7 +165,7 @@ g_dbus_method_info_ref (GDBusMethodInfo *info)
|
||||
GDBusSignalInfo *
|
||||
g_dbus_signal_info_ref (GDBusSignalInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -185,7 +185,7 @@ g_dbus_signal_info_ref (GDBusSignalInfo *info)
|
||||
GDBusPropertyInfo *
|
||||
g_dbus_property_info_ref (GDBusPropertyInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -205,7 +205,7 @@ g_dbus_property_info_ref (GDBusPropertyInfo *info)
|
||||
GDBusArgInfo *
|
||||
g_dbus_arg_info_ref (GDBusArgInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -225,7 +225,7 @@ g_dbus_arg_info_ref (GDBusArgInfo *info)
|
||||
GDBusAnnotationInfo *
|
||||
g_dbus_annotation_info_ref (GDBusAnnotationInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return info;
|
||||
g_atomic_int_inc (&info->ref_count);
|
||||
return info;
|
||||
@ -258,7 +258,7 @@ free_null_terminated_array (gpointer array, GDestroyNotify unref_func)
|
||||
void
|
||||
g_dbus_annotation_info_unref (GDBusAnnotationInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -282,7 +282,7 @@ g_dbus_annotation_info_unref (GDBusAnnotationInfo *info)
|
||||
void
|
||||
g_dbus_arg_info_unref (GDBusArgInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -306,7 +306,7 @@ g_dbus_arg_info_unref (GDBusArgInfo *info)
|
||||
void
|
||||
g_dbus_method_info_unref (GDBusMethodInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -331,7 +331,7 @@ g_dbus_method_info_unref (GDBusMethodInfo *info)
|
||||
void
|
||||
g_dbus_signal_info_unref (GDBusSignalInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -355,7 +355,7 @@ g_dbus_signal_info_unref (GDBusSignalInfo *info)
|
||||
void
|
||||
g_dbus_property_info_unref (GDBusPropertyInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -379,7 +379,7 @@ g_dbus_property_info_unref (GDBusPropertyInfo *info)
|
||||
void
|
||||
g_dbus_interface_info_unref (GDBusInterfaceInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
@ -405,7 +405,7 @@ g_dbus_interface_info_unref (GDBusInterfaceInfo *info)
|
||||
void
|
||||
g_dbus_node_info_unref (GDBusNodeInfo *info)
|
||||
{
|
||||
if (info->ref_count == -1)
|
||||
if (g_atomic_int_get (&info->ref_count) == -1)
|
||||
return;
|
||||
if (g_atomic_int_dec_and_test (&info->ref_count))
|
||||
{
|
||||
|
@ -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;
|
||||
@ -679,9 +680,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. "
|
||||
@ -715,9 +715,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;
|
||||
}
|
||||
@ -757,7 +756,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);
|
||||
|
||||
@ -814,7 +813,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);
|
||||
|
||||
@ -1090,7 +1089,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);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <glib/gthread.h>
|
||||
#include <glib/gslice.h>
|
||||
#include <glib/ghash.h>
|
||||
#include <glib/grefcount.h>
|
||||
|
||||
/* < private >
|
||||
* GVariantTypeInfo:
|
||||
@ -76,7 +77,7 @@ typedef struct
|
||||
GVariantTypeInfo info;
|
||||
|
||||
gchar *type_string;
|
||||
gint ref_count;
|
||||
gatomicrefcount ref_count;
|
||||
} ContainerInfo;
|
||||
|
||||
/* For 'array' and 'maybe' types, we store some extra information on the
|
||||
@ -167,7 +168,7 @@ g_variant_type_info_check (const GVariantTypeInfo *info,
|
||||
ContainerInfo *container = (ContainerInfo *) info;
|
||||
|
||||
/* extra checks for containers */
|
||||
g_assert_cmpint (g_atomic_int_get (&container->ref_count), >, 0);
|
||||
g_assert (!g_atomic_ref_count_compare (&container->ref_count, 0));
|
||||
g_assert (container->type_string != NULL);
|
||||
}
|
||||
else
|
||||
@ -788,7 +789,7 @@ g_variant_type_info_get (const GVariantType *type)
|
||||
|
||||
info = (GVariantTypeInfo *) container;
|
||||
container->type_string = type_string;
|
||||
container->ref_count = 1;
|
||||
g_atomic_ref_count_init (&container->ref_count);
|
||||
|
||||
g_hash_table_insert (g_variant_type_info_table, type_string, info);
|
||||
type_string = NULL;
|
||||
@ -834,8 +835,7 @@ g_variant_type_info_ref (GVariantTypeInfo *info)
|
||||
{
|
||||
ContainerInfo *container = (ContainerInfo *) info;
|
||||
|
||||
g_assert_cmpint (g_atomic_int_get (&container->ref_count), >, 0);
|
||||
g_atomic_int_inc (&container->ref_count);
|
||||
g_atomic_ref_count_inc (&container->ref_count);
|
||||
}
|
||||
|
||||
return info;
|
||||
@ -858,7 +858,7 @@ g_variant_type_info_unref (GVariantTypeInfo *info)
|
||||
ContainerInfo *container = (ContainerInfo *) info;
|
||||
|
||||
g_rec_mutex_lock (&g_variant_type_info_lock);
|
||||
if (g_atomic_int_dec_and_test (&container->ref_count))
|
||||
if (g_atomic_ref_count_dec (&container->ref_count))
|
||||
{
|
||||
g_hash_table_remove (g_variant_type_info_table,
|
||||
container->type_string);
|
||||
|
Loading…
x
Reference in New Issue
Block a user