[sysprof] libsysprof-ui: remove use of GAtomicRCBox
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] libsysprof-ui: remove use of GAtomicRCBox
- Date: Thu, 20 Feb 2020 19:26:30 +0000 (UTC)
commit f25c573ba68e92b2081fc6df4f6ce43f0121f497
Author: Christian Hergert <chergert redhat com>
Date: Thu Feb 20 11:02:49 2020 -0800
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.
src/libsysprof-ui/pointcache.c | 22 +++++++++++++++++-----
src/libsysprof-ui/sysprof-depth-visualizer.c | 13 ++++---------
2 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/src/libsysprof-ui/pointcache.c b/src/libsysprof-ui/pointcache.c
index 8072ac1..c16304f 100644
--- a/src/libsysprof-ui/pointcache.c
+++ b/src/libsysprof-ui/pointcache.c
@@ -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;
diff --git a/src/libsysprof-ui/sysprof-depth-visualizer.c b/src/libsysprof-ui/sysprof-depth-visualizer.c
index 39ebf37..118489d 100644
--- a/src/libsysprof-ui/sysprof-depth-visualizer.c
+++ b/src/libsysprof-ui/sysprof-depth-visualizer.c
@@ -55,16 +55,11 @@ static void sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self);
G_DEFINE_TYPE (SysprofDepthVisualizer, sysprof_depth_visualizer, SYSPROF_TYPE_VISUALIZER)
static void
-state_clear (State *st)
+state_free (State *st)
{
g_clear_pointer (&st->reader, sysprof_capture_reader_unref);
g_clear_pointer (&st->pc, point_cache_unref);
-}
-
-static void
-state_unref (State *st)
-{
- g_atomic_rc_box_release_full (st, (GDestroyNotify) state_clear);
+ g_slice_free (State, st);
}
static gboolean
@@ -201,7 +196,7 @@ sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self)
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
- st = g_atomic_rc_box_new0 (State);
+ st = g_slice_new0 (State);
st->reader = sysprof_capture_reader_ref (self->reader);
st->pc = point_cache_new ();
st->max_n_addrs = 0;
@@ -215,7 +210,7 @@ sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self)
task = g_task_new (self, NULL, apply_point_cache_cb, NULL);
g_task_set_source_tag (task, sysprof_depth_visualizer_reload);
- g_task_set_task_data (task, st, (GDestroyNotify) state_unref);
+ g_task_set_task_data (task, st, (GDestroyNotify) state_free);
g_task_run_in_thread (task, sysprof_depth_visualizer_worker);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]