[pango/fix-lilypond-leak: 17/17] fc: Don't use GTask for threading
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/fix-lilypond-leak: 17/17] fc: Don't use GTask for threading
- Date: Mon, 10 May 2021 10:50:35 +0000 (UTC)
commit ac4d8f2964299d14046cb6dd465ad05c87439b29
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 | 55 +++++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 31 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index f74b2c15..7c307bfb 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);
+ thread = g_thread_new ("[pango] FcFontSetMatch", match_in_thread, thread_data_new (pats));
+ g_thread_unref (thread);
- 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] FcFontSetSort", sort_in_thread, thread_data_new (pats));
+ g_thread_unref (thread);
g_hash_table_insert (fontmap->priv->patterns_hash,
pats->pattern, pats);
@@ -1344,11 +1340,8 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFcFontMap, pango_fc_font_map, PANGO_TYPE_
G_ADD_PRIVATE (PangoFcFontMap)
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
pango_fc_font_map_list_model_init))
-static void
-init_in_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
+static gpointer
+init_in_thread (gpointer task_data)
{
gint64 before = PANGO_TRACE_CURRENT_TIME;
@@ -1360,6 +1353,8 @@ init_in_thread (GTask *task,
fc_initialized = 2;
g_cond_broadcast (&fc_init_cond);
g_mutex_unlock (&fc_init_mutex);
+
+ return NULL;
}
static void
@@ -1369,13 +1364,11 @@ start_init_in_thread (PangoFcFontMap *fcfontmap)
if (fc_initialized == 0)
{
- GTask *task;
+ GThread *thread;
fc_initialized = 1;
- task = g_task_new (fcfontmap, NULL, NULL, NULL);
- g_task_set_name (task, "[pango] FcInit");
- g_task_run_in_thread (task, init_in_thread);
- g_object_unref (task);
+ thread = g_thread_new ("[pango] FcInit", init_in_thread, NULL);
+ g_thread_unref (thread);
}
g_mutex_unlock (&fc_init_mutex);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]