[pango/speed-up-format-filtering] Fix up threading issues




commit c24f2e78173b2aea855aa7c3b135c8355cec2933
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Aug 19 11:08:46 2020 -0400

    Fix up threading issues
    
    When passing the fontsets to a thread, we must make
    sure they stick around until the threads are done,
    so make a copy, and ref the patterns.
    
    This fixes tests-pangocairo-threads crashing.

 pango/pangofc-fontmap.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 774cd871..fd1256a3 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -756,9 +756,25 @@ struct _PangoFcPatterns {
   FcFontSet *fontset;
 };
 
+static FcFontSet *
+font_set_copy (FcFontSet *set)
+{
+  FcFontSet *copy;
+  int i;
+
+  copy = malloc (sizeof (FcFontSet));
+  copy->sfont = copy->nfont = set->nfont;
+  copy->fonts = malloc (sizeof (FcPattern *) * copy->nfont);
+  memcpy (copy->fonts, set->fonts, sizeof (FcPattern *) * copy->nfont);
+  for (i = 0; i < copy->nfont; i++)
+    FcPatternReference (copy->fonts[i]);
+
+  return copy;
+}
+
 typedef struct {
   FcConfig *config;
-  FcFontSet **sets;
+  FcFontSet *sets[2];
   int nsets;
   FcPattern *pattern;
   PangoFcPatterns *patterns;
@@ -771,13 +787,16 @@ static ThreadData *
 thread_data_new (PangoFcPatterns *patterns)
 {
   ThreadData *td;
+  FcFontSet **sets;
+  int i;
 
   td = g_new (ThreadData, 1);
   td->patterns = pango_fc_patterns_ref (patterns);
-  td->pattern = patterns->pattern;
+  td->pattern = FcPatternDuplicate (patterns->pattern);
   td->config = FcConfigReference (pango_fc_font_map_get_config (patterns->fontmap));
-  /* FIXME: FcFontSet not refcounted */
-  td->sets = pango_fc_font_map_get_config_fonts (patterns->fontmap, &td->nsets);
+  sets = pango_fc_font_map_get_config_fonts (patterns->fontmap, &td->nsets);
+  for (i = 0; i < td->nsets; i++)
+    td->sets[i] = font_set_copy (sets[i]);
 
   return td;
 }
@@ -786,7 +805,11 @@ static void
 thread_data_free (gpointer data)
 {
   ThreadData *td = data;
+  int i;
 
+  for (i = 0; i < td->nsets; i++)
+    FcFontSetDestroy (td->sets[i]);
+  FcPatternDestroy (td->pattern);
   FcConfigDestroy (td->config);
   pango_fc_patterns_unref (td->patterns);
   g_free (td);
@@ -832,8 +855,6 @@ sort_in_thread (GTask        *task,
 
   g_mutex_lock (&td->patterns->mutex);
   td->patterns->fontset = fontset;
-  FcPatternDestroy (td->patterns->match);
-  td->patterns->match = NULL;
   g_cond_signal (&td->patterns->cond);
   g_mutex_unlock (&td->patterns->mutex);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]