libsysprof-ui: remove use of GAtomicRCBox

Switching this to use an embedded ref count allows us to backport to
operating systems restricted to GLib 2.56.
This commit is contained in:
Christian Hergert
2020-02-20 11:02:49 -08:00
parent d89a689ab4
commit f25c573ba6
2 changed files with 21 additions and 14 deletions

View File

@ -24,25 +24,36 @@
struct _PointCache
{
GHashTable *sets;
volatile gint ref_count;
GHashTable *sets;
};
static void
point_cache_clear (PointCache *self)
point_cache_finalize (PointCache *self)
{
g_clear_pointer (&self->sets, g_hash_table_unref);
g_slice_free (PointCache, self);
}
PointCache *
point_cache_ref (PointCache *self)
{
return g_atomic_rc_box_acquire (self);
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (self->ref_count > 0, NULL);
g_atomic_int_inc (&self->ref_count);
return self;
}
void
point_cache_unref (PointCache *self)
{
g_atomic_rc_box_release_full (self, (GDestroyNotify) point_cache_clear);
g_return_if_fail (self != NULL);
g_return_if_fail (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
point_cache_finalize (self);
}
PointCache *
@ -50,7 +61,8 @@ point_cache_new (void)
{
PointCache *self;
self = g_atomic_rc_box_new0 (PointCache);
self = g_slice_new0 (PointCache);
self->ref_count = 1;
self->sets = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_array_unref);
return self;