mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
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
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user