[pango: 1/2] Use GMutex for the thai_brk




commit 2743d99312fcf5831e924e1a7089712aeab54f38
Author: Peng Wu <pwu redhat com>
Date:   Thu Jul 15 11:03:15 2021 +0800

    Use GMutex for the thai_brk
    
    Use GMutex to protect the thai_brk in multithreading.

 pango/break-thai.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/pango/break-thai.c b/pango/break-thai.c
index 85b9e54a..871c0869 100644
--- a/pango/break-thai.c
+++ b/pango/break-thai.c
@@ -27,8 +27,10 @@
 #include <thai/thwchar.h>
 #include <thai/thbrk.h>
 
-#ifndef HAVE_TH_BRK_FIND_BREAKS
-G_LOCK_DEFINE_STATIC (th_brk);
+G_LOCK_DEFINE_STATIC (thai_brk);
+
+#ifdef HAVE_TH_BRK_FIND_BREAKS
+static ThBrk *thai_brk = NULL;
 #endif
 
 /*
@@ -79,13 +81,15 @@ break_thai (const char          *text,
 
   /* find line break positions */
 
+  G_LOCK (thai_brk);
 #ifdef HAVE_TH_BRK_FIND_BREAKS
-  len = th_brk_find_breaks(NULL, tis_text, brk_pnts, cnt);
+  if (thai_brk == NULL)
+    thai_brk = th_brk_new(NULL);
+  len = th_brk_find_breaks(thai_brk, tis_text, brk_pnts, cnt);
 #else
-  G_LOCK (th_brk);
   len = th_brk (tis_text, brk_pnts, cnt);
-  G_UNLOCK (th_brk);
 #endif
+  G_UNLOCK (thai_brk);
 
   for (cnt = 0; cnt < len; cnt++)
     if (attrs[brk_pnts[cnt]].is_char_break)


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