[pango/threadsafe-failed-attempt: 10/11] Remove "Work around bug #686192" hacks



commit 97444dda54d7ac3a7b40bd4323d0e535fad625b7
Author: Behdad Esfahbod <behdad behdad org>
Date:   Mon Oct 29 02:16:09 2012 -0700

    Remove "Work around bug #686192" hacks
    
    Properly initialize non-static mutexes.

 pango/pango-threadsafe.h |   19 ++++++++++++++++---
 pango/pangofc-fontmap.c  |   28 +++++++++++-----------------
 2 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/pango/pango-threadsafe.h b/pango/pango-threadsafe.h
index 57e823d..a0f096f 100644
--- a/pango/pango-threadsafe.h
+++ b/pango/pango-threadsafe.h
@@ -59,9 +59,7 @@ PHashTable* p_hash_table_new_full          (GHashFunc       hash_func,
 				 key_destroy_func,
 				 value_destroy_func);
 
-  /* Work around bug #686192 */
-  g_mutex_lock (&p->mx);
-  g_mutex_unlock (&p->mx);
+  g_mutex_init (&p->mx);
 
   return p;
 }
@@ -123,6 +121,21 @@ gboolean    p_hash_table_remove            (PHashTable     *hash_table,
 }
 
 static inline
+gboolean    p_hash_table_remove_if_is      (PHashTable     *hash_table,
+                                            gconstpointer   key,
+					    gconstpointer   value)
+{
+  gboolean ret;
+  g_mutex_lock (&hash_table->mx);
+  if (value != g_hash_table_lookup (hash_table->ht, key))
+    ret = FALSE;
+  else
+    ret = g_hash_table_remove (hash_table->ht, key);
+  g_mutex_unlock (&hash_table->mx);
+  return ret;
+}
+
+static inline
 gpointer    p_hash_table_lookup            (PHashTable     *hash_table,
                                             gconstpointer   key)
 {
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 22d9f0c..6c71974 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -725,12 +725,10 @@ pango_fc_patterns_unref (PangoFcPatterns *pats)
   if (!g_atomic_int_dec_and_test (&pats->ref_count))
     return;
 
-  /* Only remove from fontmap hash if we are in it.  This is not necessarily
-   * the case after a cache_clear() call. */
-  if (pats->fontmap->priv->patterns_hash &&
-      pats == p_hash_table_lookup (pats->fontmap->priv->patterns_hash, pats->pattern))
-    p_hash_table_remove (pats->fontmap->priv->patterns_hash,
-			 pats->pattern);
+  if (pats->fontmap->priv->patterns_hash)
+    p_hash_table_remove_if_is (pats->fontmap->priv->patterns_hash,
+			       pats->pattern,
+			       pats);
 
   if (pats->pattern)
     FcPatternDestroy (pats->pattern);
@@ -912,6 +910,7 @@ pango_fc_fontset_init (PangoFcFontset *fontset)
 {
   fontset->fonts = g_ptr_array_new ();
   fontset->coverages = g_ptr_array_new ();
+  g_mutex_init (&fontset->lock);
 }
 
 static void
@@ -942,9 +941,7 @@ pango_fc_fontset_finalize (GObject *object)
   if (fontset->patterns)
     pango_fc_patterns_unref (fontset->patterns);
 
-  if (fontset->lock.p) /* Work around bug 686192 */
-    g_mutex_clear (&fontset->lock);
-
+  g_mutex_clear (&fontset->lock);
 
   G_OBJECT_CLASS (pango_fc_fontset_parent_class)->finalize (object);
 }
@@ -1056,6 +1053,7 @@ pango_fc_font_map_init (PangoFcFontMap *fcfontmap)
 					      NULL,
 					      (GDestroyNotify)g_object_unref);
   priv->fontset_cache = g_queue_new ();
+  g_mutex_init (&priv->fontset_cache_lock);
 
   priv->patterns_hash = p_hash_table_new (NULL, NULL);
 
@@ -1080,8 +1078,7 @@ pango_fc_font_map_fini (PangoFcFontMap *fcfontmap)
   g_queue_free (priv->fontset_cache);
   priv->fontset_cache = NULL;
 
-  if (priv->fontset_cache_lock.p) /* Work around bug 686192 */
-    g_mutex_clear (&priv->fontset_cache_lock);
+  g_mutex_clear (&priv->fontset_cache_lock);
 
   p_hash_table_destroy (priv->fontset_hash);
   priv->fontset_hash = NULL;
@@ -1234,11 +1231,8 @@ _pango_fc_font_map_remove (PangoFcFontMap *fcfontmap,
     {
       /* Only remove from fontmap hash if we are in it.  This is not necessarily
        * the case after a cache_clear() call. */
-      if (priv->font_hash &&
-	  fcfont == p_hash_table_lookup (priv->font_hash, key))
-        {
-	  p_hash_table_remove (priv->font_hash, key);
-	}
+      if (priv->font_hash)
+	p_hash_table_remove_if_is (priv->font_hash, key, fcfont);
       _pango_fc_font_set_font_key (fcfont, NULL);
       pango_fc_font_key_free (key);
     }
@@ -1729,7 +1723,7 @@ pango_fc_fontset_cache (PangoFcFontset *fontset,
 	{
 	  PangoFcFontset *tmp_fontset = g_queue_pop_tail (cache);
 	  tmp_fontset->cache_link = NULL;
-	  p_hash_table_remove (priv->fontset_hash, tmp_fontset->key);
+	  p_hash_table_remove_if_is (priv->fontset_hash, tmp_fontset->key, tmp_fontset);
 	}
 
       fontset->cache_link = g_list_prepend (NULL, fontset);



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