[pango/fix-lilypond-leak] fc: Don't use GTask for threading




commit d10ed4abc13ee15ff2700c991bfb9402f493b31e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 9 15:12:50 2021 -0400

    fc: Don't use GTask for threading
    
    GTask requires a running mainloop, otherwise we
    end up leaking task objects and their associated
    data. This is not a problem in GTK applications,
    but it does show up in batch operation, such as
    with lilypond.
    
    To avoid this problem, use plain threads.

 pango/pangofc-fontmap.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 7966a8cd..b20a4f79 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -820,11 +820,8 @@ thread_data_free (gpointer data)
   g_object_unref (fontmap);
 }
 
-static void
-match_in_thread (GTask        *task,
-                 gpointer      source_object,
-                 gpointer      task_data,
-                 GCancellable *cancellable)
+static gpointer
+match_in_thread (gpointer task_data)
 {
   ThreadData *td = task_data;
   FcResult result;
@@ -842,13 +839,14 @@ match_in_thread (GTask        *task,
   td->patterns->match = match;
   g_cond_signal (&td->patterns->cond);
   g_mutex_unlock (&td->patterns->mutex);
+
+  thread_data_free (td);
+
+  return NULL;
 }
 
-static void
-sort_in_thread (GTask        *task,
-                gpointer      source_object,
-                gpointer      task_data,
-                GCancellable *cancellable)
+static gpointer
+sort_in_thread (gpointer task_data)
 {
   ThreadData *td = task_data;
   FcResult result;
@@ -868,13 +866,17 @@ sort_in_thread (GTask        *task,
   td->patterns->fontset = fontset;
   g_cond_signal (&td->patterns->cond);
   g_mutex_unlock (&td->patterns->mutex);
+
+  thread_data_free (td);
+
+  return NULL;
 }
 
 static PangoFcPatterns *
 pango_fc_patterns_new (FcPattern *pat, PangoFcFontMap *fontmap)
 {
   PangoFcPatterns *pats;
-  GTask *task;
+  GThread *thread;
 
   pat = uniquify_pattern (fontmap, pat);
   pats = g_hash_table_lookup (fontmap->priv->patterns_hash, pat);
@@ -892,17 +894,11 @@ pango_fc_patterns_new (FcPattern *pat, PangoFcFontMap *fontmap)
   g_mutex_init (&pats->mutex);
   g_cond_init (&pats->cond);
 
-  task = g_task_new (NULL, NULL, NULL, NULL);
-  g_task_set_name (task, "[pango] FcFontSetMatch");
-  g_task_set_task_data (task, thread_data_new (pats), thread_data_free);
-  g_task_run_in_thread (task, match_in_thread);
-  g_object_unref (task);
-
-  task = g_task_new (NULL, NULL, NULL, NULL);
-  g_task_set_name (task, "[pango] FcFontSetSort");
-  g_task_set_task_data (task, thread_data_new (pats), thread_data_free);
-  g_task_run_in_thread (task, sort_in_thread);
-  g_object_unref (task);
+  thread = g_thread_new ("[pango] FcFontSetMatch", match_in_thread, thread_data_new (pats));
+  g_thread_unref (thread);
+
+  thread = g_thread_new ("[pango] FcFontSetSort", sort_in_thread, thread_data_new (pats));
+  g_thread_unref (thread);
 
   g_hash_table_insert (fontmap->priv->patterns_hash,
                        pats->pattern, pats);


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