[pango/threadsafe-failed-attempt: 8/11] Make some pangofc hash caches really threadsafe
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/threadsafe-failed-attempt: 8/11] Make some pangofc hash caches really threadsafe
- Date: Thu, 15 Nov 2012 19:18:15 +0000 (UTC)
commit 1b705389d7c15f461ebf0460e2b08f982c482667
Author: Behdad Esfahbod <behdad behdad org>
Date: Mon Oct 15 21:25:15 2012 -0500
Make some pangofc hash caches really threadsafe
pango/pango-threadsafe.h | 14 ++++++++++++++
pango/pangofc-fontmap.c | 17 ++++++++++-------
2 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/pango/pango-threadsafe.h b/pango/pango-threadsafe.h
index bc18074..cf8b425 100644
--- a/pango/pango-threadsafe.h
+++ b/pango/pango-threadsafe.h
@@ -117,6 +117,20 @@ gpointer p_hash_table_lookup (PHashTable *hash_table,
}
static inline
+gpointer p_hash_table_lookup_ref (PHashTable *hash_table,
+ gconstpointer key,
+ gpointer (*ref_func) (gpointer))
+{
+ gpointer ret;
+ g_mutex_lock (&hash_table->mx);
+ ret = g_hash_table_lookup (hash_table->ht, key);
+ if (ret)
+ ref_func (ret);
+ g_mutex_unlock (&hash_table->mx);
+ return ret;
+}
+
+static inline
void p_hash_table_foreach (PHashTable *hash_table,
GHFunc func,
gpointer user_data)
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 84f2b94..2e031a8 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -689,9 +689,9 @@ pango_fc_patterns_new (FcPattern *pat, PangoFcFontMap *fontmap)
PangoFcPatterns *pats;
pat = uniquify_pattern (fontmap, pat);
- pats = p_hash_table_lookup (fontmap->priv->patterns_hash, pat);
+ pats = p_hash_table_lookup_ref (fontmap->priv->patterns_hash, pat, pango_fc_patterns_ref);
if (pats)
- return pango_fc_patterns_ref (pats);
+ return pats;
pats = g_slice_new0 (PangoFcPatterns);
@@ -1218,6 +1218,7 @@ pango_fc_font_map_add (PangoFcFontMap *fcfontmap,
key_copy = pango_fc_font_key_copy (key);
_pango_fc_font_set_font_key (fcfont, key_copy);
+ /* XXXXXXXXXXX racy here? */
p_hash_table_insert (priv->font_hash, key_copy, fcfont);
}
@@ -1508,6 +1509,7 @@ uniquify_pattern (PangoFcFontMap *fcfontmap,
PangoFcFontMapPrivate *priv = fcfontmap->priv;
FcPattern *old_pattern;
+ /* XXXXXX racy here? */
old_pattern = p_hash_table_lookup (priv->pattern_hash, pattern);
if (old_pattern)
{
@@ -1539,9 +1541,9 @@ pango_fc_font_map_new_font (PangoFcFontMap *fcfontmap,
pango_fc_font_key_init (&key, fcfontmap, fontset_key, match);
- fcfont = p_hash_table_lookup (priv->font_hash, &key);
+ fcfont = p_hash_table_lookup_ref (priv->font_hash, &key, g_object_ref);
if (fcfont)
- return g_object_ref (fcfont);
+ return fcfont;
class = PANGO_FC_FONT_MAP_GET_CLASS (fcfontmap);
@@ -1754,7 +1756,7 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap,
pango_fc_fontset_key_init (&key, fcfontmap, context, desc, language);
- fontset = p_hash_table_lookup (priv->fontset_hash, &key);
+ fontset = p_hash_table_lookup_ref (priv->fontset_hash, &key, g_object_ref);
if (G_UNLIKELY (!fontset))
{
@@ -1764,7 +1766,7 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap,
return NULL;
fontset = pango_fc_fontset_new (&key, patterns);
- p_hash_table_insert (priv->fontset_hash, pango_fc_fontset_get_key (fontset), fontset);
+ p_hash_table_insert (priv->fontset_hash, pango_fc_fontset_get_key (fontset), g_object_ref (fontset));
pango_fc_patterns_unref (patterns);
}
@@ -1773,7 +1775,7 @@ pango_fc_font_map_load_fontset (PangoFontMap *fontmap,
pango_font_description_free (key.desc);
- return g_object_ref (fontset);
+ return fontset;
}
/**
@@ -1812,6 +1814,7 @@ pango_fc_font_map_get_font_face_data (PangoFcFontMap *fcfontmap,
if (FcPatternGetInteger (font_pattern, FC_INDEX, 0, &key.id) != FcResultMatch)
return NULL;
+ /* XXXXXXXXXX racy here */
data = p_hash_table_lookup (priv->font_face_data_hash, &key);
if (G_LIKELY (data))
return data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]