st: Stop implementing custom refcounting
Glib has generic RcBox/ArcBox types nowadays that can be used to add ref-counting to a plain struct types, use those instead. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2679>
This commit is contained in:
parent
b6a7cac28f
commit
74c5bb270d
@ -43,34 +43,29 @@
|
||||
|
||||
|
||||
struct _StIconCache {
|
||||
int ref_count;
|
||||
|
||||
GMappedFile *map;
|
||||
char *buffer;
|
||||
|
||||
guint32 last_chain_offset;
|
||||
};
|
||||
|
||||
static void
|
||||
clear_icon_cache (gpointer data)
|
||||
{
|
||||
StIconCache *cache = data;
|
||||
g_clear_pointer (&cache->map, g_mapped_file_unref);
|
||||
}
|
||||
|
||||
StIconCache *
|
||||
st_icon_cache_ref (StIconCache *cache)
|
||||
{
|
||||
cache->ref_count++;
|
||||
return cache;
|
||||
return g_atomic_rc_box_acquire (cache);
|
||||
}
|
||||
|
||||
void
|
||||
st_icon_cache_unref (StIconCache *cache)
|
||||
{
|
||||
cache->ref_count --;
|
||||
|
||||
if (cache->ref_count == 0)
|
||||
{
|
||||
g_debug ("unmapping icon cache");
|
||||
|
||||
if (cache->map)
|
||||
g_mapped_file_unref (cache->map);
|
||||
g_free (cache);
|
||||
}
|
||||
g_atomic_rc_box_release_full (cache, clear_icon_cache);
|
||||
}
|
||||
|
||||
StIconCache *
|
||||
@ -115,8 +110,7 @@ st_icon_cache_new_for_path (const char *path)
|
||||
|
||||
g_debug ("found icon cache for %s", path);
|
||||
|
||||
cache = g_new0 (StIconCache, 1);
|
||||
cache->ref_count = 1;
|
||||
cache = g_atomic_rc_box_new0 (StIconCache);
|
||||
cache->map = map;
|
||||
cache->buffer = g_mapped_file_get_contents (map);
|
||||
|
||||
@ -133,9 +127,7 @@ st_icon_cache_new (const char *data)
|
||||
{
|
||||
StIconCache *cache;
|
||||
|
||||
cache = g_new0 (StIconCache, 1);
|
||||
cache->ref_count = 1;
|
||||
cache->map = NULL;
|
||||
cache = g_atomic_rc_box_new0 (StIconCache);
|
||||
cache->buffer = (char *)data;
|
||||
|
||||
return cache;
|
||||
|
@ -31,12 +31,7 @@
|
||||
StIconColors *
|
||||
st_icon_colors_new (void)
|
||||
{
|
||||
StIconColors *colors;
|
||||
|
||||
colors = g_new0 (StIconColors, 1);
|
||||
colors->ref_count = 1;
|
||||
|
||||
return colors;
|
||||
return g_atomic_rc_box_new0 (StIconColors);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,10 +46,8 @@ StIconColors *
|
||||
st_icon_colors_ref (StIconColors *colors)
|
||||
{
|
||||
g_return_val_if_fail (colors != NULL, NULL);
|
||||
g_return_val_if_fail (colors->ref_count > 0, colors);
|
||||
|
||||
g_atomic_int_inc ((volatile int *)&colors->ref_count);
|
||||
return colors;
|
||||
return g_atomic_rc_box_acquire (colors);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,10 +62,8 @@ void
|
||||
st_icon_colors_unref (StIconColors *colors)
|
||||
{
|
||||
g_return_if_fail (colors != NULL);
|
||||
g_return_if_fail (colors->ref_count > 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test ((volatile int *)&colors->ref_count))
|
||||
g_free (colors);
|
||||
g_atomic_rc_box_release (colors);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,8 +21,6 @@ typedef struct _StIconColors StIconColors;
|
||||
* icon.
|
||||
*/
|
||||
struct _StIconColors {
|
||||
volatile guint ref_count;
|
||||
|
||||
ClutterColor foreground;
|
||||
ClutterColor warning;
|
||||
ClutterColor error;
|
||||
|
@ -59,7 +59,7 @@ st_shadow_new (ClutterColor *color,
|
||||
{
|
||||
StShadow *shadow;
|
||||
|
||||
shadow = g_new (StShadow, 1);
|
||||
shadow = g_atomic_rc_box_new (StShadow);
|
||||
|
||||
shadow->color = *color;
|
||||
shadow->xoffset = xoffset;
|
||||
@ -67,7 +67,6 @@ st_shadow_new (ClutterColor *color,
|
||||
shadow->blur = blur;
|
||||
shadow->spread = spread;
|
||||
shadow->inset = inset;
|
||||
shadow->ref_count = 1;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
@ -84,10 +83,8 @@ StShadow *
|
||||
st_shadow_ref (StShadow *shadow)
|
||||
{
|
||||
g_return_val_if_fail (shadow != NULL, NULL);
|
||||
g_return_val_if_fail (shadow->ref_count > 0, shadow);
|
||||
|
||||
g_atomic_int_inc (&shadow->ref_count);
|
||||
return shadow;
|
||||
return g_atomic_rc_box_acquire (shadow);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,10 +99,8 @@ void
|
||||
st_shadow_unref (StShadow *shadow)
|
||||
{
|
||||
g_return_if_fail (shadow != NULL);
|
||||
g_return_if_fail (shadow->ref_count > 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&shadow->ref_count))
|
||||
g_free (shadow);
|
||||
g_atomic_rc_box_release (shadow);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,6 @@ struct _StShadow {
|
||||
gdouble blur;
|
||||
gdouble spread;
|
||||
gboolean inset;
|
||||
volatile int ref_count;
|
||||
};
|
||||
|
||||
GType st_shadow_get_type (void) G_GNUC_CONST;
|
||||
|
Loading…
x
Reference in New Issue
Block a user