[pango: 2/4] Use atomic reference counting for PangoFcPatterns
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango: 2/4] Use atomic reference counting for PangoFcPatterns
- Date: Fri, 2 Jul 2021 03:42:17 +0000 (UTC)
commit 27210a3039144e5ac15c1cd902591168805e09d9
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Jul 1 19:21:25 2021 -0500
Use atomic reference counting for PangoFcPatterns
There was a data race in accessing the ref_count of this struct; now
with g_atomic_rc_box it's done properly across threads.
Fixes https://gitlab.gnome.org/GNOME/pango/-/issues/571
pango/pangofc-fontmap.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index ade1b38a..4be8502e 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -743,8 +743,6 @@ pango_fc_font_key_get_variations (const PangoFcFontKey *key)
*/
struct _PangoFcPatterns {
- guint ref_count;
-
PangoFcFontMap *fontmap;
/* match and fontset are initialized in a thread,
@@ -883,11 +881,10 @@ pango_fc_patterns_new (FcPattern *pat, PangoFcFontMap *fontmap)
if (pats)
return pango_fc_patterns_ref (pats);
- pats = g_slice_new0 (PangoFcPatterns);
+ pats = g_atomic_rc_box_new0 (PangoFcPatterns);
pats->fontmap = fontmap;
- pats->ref_count = 1;
FcPatternReference (pat);
pats->pattern = pat;
@@ -909,11 +906,7 @@ pango_fc_patterns_new (FcPattern *pat, PangoFcFontMap *fontmap)
static PangoFcPatterns *
pango_fc_patterns_ref (PangoFcPatterns *pats)
{
- g_return_val_if_fail (pats->ref_count > 0, NULL);
-
- pats->ref_count++;
-
- return pats;
+ return g_atomic_rc_box_acquire (pats);
}
static void
@@ -944,15 +937,7 @@ free_patterns (gpointer data)
static void
pango_fc_patterns_unref (PangoFcPatterns *pats)
{
- g_return_if_fail (pats->ref_count > 0);
-
- pats->ref_count--;
-
- if (pats->ref_count)
- return;
-
- free_patterns (pats);
- g_slice_free (PangoFcPatterns, pats);
+ g_atomic_rc_box_release_full (pats, free_patterns);
}
static FcPattern *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]