[sysprof] ui: use g_atomic_rc_box
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] ui: use g_atomic_rc_box
- Date: Wed, 8 Jan 2020 19:13:24 +0000 (UTC)
commit bd2da8baa06e3df51f8ad021d2404f6848a74214
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 8 11:00:54 2020 -0800
ui: use g_atomic_rc_box
This changes a couple of our structures to use the atomic rc box instead
of gslice directly. It shouldn't affect anything, just some general
modernization while looking at #23
src/libsysprof-ui/pointcache.c | 15 ++++-----------
src/libsysprof-ui/sysprof-depth-visualizer.c | 13 +++++++++----
2 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/src/libsysprof-ui/pointcache.c b/src/libsysprof-ui/pointcache.c
index 6c902a8..8072ac1 100644
--- a/src/libsysprof-ui/pointcache.c
+++ b/src/libsysprof-ui/pointcache.c
@@ -24,31 +24,25 @@
struct _PointCache
{
- volatile gint ref_count;
GHashTable *sets;
};
static void
-point_cache_destroy (PointCache *self)
+point_cache_clear (PointCache *self)
{
g_clear_pointer (&self->sets, g_hash_table_unref);
- g_slice_free (PointCache, self);
}
PointCache *
point_cache_ref (PointCache *self)
{
- g_return_val_if_fail (self->ref_count > 0, NULL);
- g_atomic_int_inc (&self->ref_count);
- return self;
+ return g_atomic_rc_box_acquire (self);
}
void
point_cache_unref (PointCache *self)
{
- g_return_if_fail (self->ref_count > 0);
- if (g_atomic_int_dec_and_test (&self->ref_count))
- point_cache_destroy (self);
+ g_atomic_rc_box_release_full (self, (GDestroyNotify) point_cache_clear);
}
PointCache *
@@ -56,8 +50,7 @@ point_cache_new (void)
{
PointCache *self;
- self = g_slice_new0 (PointCache);
- self->ref_count = 1;
+ self = g_atomic_rc_box_new0 (PointCache);
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 08183eb..8fab70e 100644
--- a/src/libsysprof-ui/sysprof-depth-visualizer.c
+++ b/src/libsysprof-ui/sysprof-depth-visualizer.c
@@ -51,11 +51,16 @@ typedef struct
G_DEFINE_TYPE (SysprofDepthVisualizer, sysprof_depth_visualizer, SYSPROF_TYPE_VISUALIZER)
static void
-state_free (State *st)
+state_clear (State *st)
{
g_clear_pointer (&st->reader, sysprof_capture_reader_unref);
g_clear_pointer (&st->pc, point_cache_unref);
- g_slice_free (State, st);
+}
+
+static void
+state_unref (State *st)
+{
+ g_atomic_rc_box_release_full (st, (GDestroyNotify) state_clear);
}
static gboolean
@@ -179,7 +184,7 @@ sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self)
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
- st = g_slice_new0 (State);
+ st = g_atomic_rc_box_new0 (State);
st->reader = sysprof_capture_reader_ref (self->reader);
st->pc = point_cache_new ();
st->max_n_addrs = 0;
@@ -193,7 +198,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_free);
+ g_task_set_task_data (task, st, (GDestroyNotify) state_unref);
g_task_run_in_thread (task, sysprof_depth_visualizer_worker);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]