[pango/threadsafe-failed-attempt: 5/11] Make PangoFcFontSet threadsafe
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/threadsafe-failed-attempt: 5/11] Make PangoFcFontSet threadsafe
- Date: Thu, 15 Nov 2012 19:18:00 +0000 (UTC)
commit 0336db39ebbd94a2ba53370e188b40dcab6b9a32
Author: Behdad Esfahbod <behdad behdad org>
Date: Mon Oct 15 19:56:42 2012 -0500
Make PangoFcFontSet threadsafe
pango/pangofc-fontmap.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 5be2b81..6e47d08 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -811,6 +811,8 @@ struct _PangoFcFontset
GPtrArray *coverages;
GList *cache_link;
+
+ GMutex lock;
};
typedef PangoFontsetClass PangoFcFontsetClass;
@@ -873,13 +875,21 @@ static PangoFont *
pango_fc_fontset_get_font_at (PangoFcFontset *fontset,
unsigned int i)
{
- while (i >= fontset->fonts->len)
+ /* Meh, mixing atomic and mutexes in a haphazard way... */
+ int len = g_atomic_int_get (&fontset->fonts->len);
+
+ if (i >= len)
{
- PangoFont *font = pango_fc_fontset_load_next_font (fontset);
- g_ptr_array_add (fontset->fonts, font);
- g_ptr_array_add (fontset->coverages, NULL);
- if (!font)
- return NULL;
+ g_mutex_lock (&fontset->lock);
+ while (i >= fontset->fonts->len)
+ {
+ PangoFont *font = pango_fc_fontset_load_next_font (fontset);
+ g_ptr_array_add (fontset->fonts, font);
+ g_ptr_array_add (fontset->coverages, NULL);
+ if (!font)
+ return NULL;
+ }
+ g_mutex_unlock (&fontset->lock);
}
return g_ptr_array_index (fontset->fonts, i);
@@ -933,6 +943,10 @@ 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_OBJECT_CLASS (pango_fc_fontset_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]