[pango/fcinit-once] Only initialize fontconfig once




commit 04038da2476ea6a52ce29ef7f300959bfc28409f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 27 14:06:05 2021 -0400

    Only initialize fontconfig once
    
    When multiple fontmaps are created in quick
    succession, we would send off a thread to call
    FcInit for each one of them, which is not really
    necessary. Just do it once.

 pango/pangofc-fontmap.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 16f10747..813b6c78 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -106,7 +106,7 @@
  */
 static GMutex fc_init_mutex;
 static GCond fc_init_cond;
-static gboolean fc_initialized;
+static int fc_initialized = 0;
 
 
 typedef struct _PangoFcFontFaceData PangoFcFontFaceData;
@@ -1357,8 +1357,28 @@ init_in_thread (GTask        *task,
   pango_trace_mark (before, "FcInit", NULL);
 
   g_mutex_lock (&fc_init_mutex);
-  fc_initialized = TRUE;
-  g_cond_signal (&fc_init_cond);
+  fc_initialized = 2;
+  g_cond_broadcast (&fc_init_cond);
+  g_mutex_unlock (&fc_init_mutex);
+}
+
+static void
+start_init_in_thread (PangoFcFontMap *fcfontmap)
+{
+  g_mutex_lock (&fc_init_mutex);
+
+  if (fc_initialized == 0)
+    {
+      GTask *task;
+
+      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);
+    }
+
   g_mutex_unlock (&fc_init_mutex);
 }
 
@@ -1369,7 +1389,7 @@ wait_for_fc_init (void)
   gboolean waited = FALSE;
 
   g_mutex_lock (&fc_init_mutex);
-  while (!fc_initialized)
+  while (fc_initialized < 2)
     {
       waited = TRUE;
       g_cond_wait (&fc_init_cond, &fc_init_mutex);
@@ -1411,15 +1431,7 @@ pango_fc_font_map_init (PangoFcFontMap *fcfontmap)
                                                     NULL);
   priv->dpi = -1;
 
-  if (!fc_initialized)
-    {
-      GTask *task;
-
-      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);
-    }
+  start_init_in_thread (fcfontmap);
 }
 
 static void


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