summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2013-01-03 03:52:09 -0600
committerBehdad Esfahbod <behdad@behdad.org>2013-01-03 03:52:09 -0600
commitdd90b07699fe5bf0ea5dfee7e907662e8ca8280b (patch)
tree9f7f2a4f1877fbcdf9f21158933f5938d26753dd
parent00997204f7df5f4e2f75f8c1c2f72130f302e7c6 (diff)
downloadpango-dd90b07699fe5bf0ea5dfee7e907662e8ca8280b.tar.gz
Make pango threadsafe!
By way of declaring fontmaps NOT threadsafe, and making pango_cairo_font_map_get_default() return a thread-private fontmap. test-pangocairo-threads doesn't crash anymore, if used with fontconfig master.
-rw-r--r--pango/pangocairo-fontmap.c33
1 files changed, 10 insertions, 23 deletions
diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c
index 1c235acb..461de9f9 100644
--- a/pango/pangocairo-fontmap.c
+++ b/pango/pangocairo-fontmap.c
@@ -66,9 +66,6 @@ pango_cairo_font_map_default_init (PangoCairoFontMapIface *iface)
PangoFontMap *
pango_cairo_font_map_new (void)
{
- /* Make sure that the type system is initialized */
- g_type_init ();
-
#if defined(HAVE_CORE_TEXT) && defined (HAVE_CAIRO_QUARTZ)
return g_object_new (PANGO_TYPE_CAIRO_CORE_TEXT_FONT_MAP, NULL);
#elif defined(HAVE_CAIRO_WIN32)
@@ -102,9 +99,6 @@ pango_cairo_font_map_new (void)
PangoFontMap *
pango_cairo_font_map_new_for_font_type (cairo_font_type_t fonttype)
{
- /* Make sure that the type system is initialized */
- g_type_init ();
-
switch ((int) fonttype)
{
#if defined(HAVE_CORE_TEXT) && defined (HAVE_CAIRO_QUARTZ)
@@ -124,7 +118,7 @@ pango_cairo_font_map_new_for_font_type (cairo_font_type_t fonttype)
}
}
-static PangoFontMap *default_font_map = NULL; /* MT-safe */
+static GPrivate default_font_map = G_PRIVATE_INIT (g_object_unref); /* MT-safe */
/**
* pango_cairo_font_map_get_default:
@@ -149,10 +143,15 @@ static PangoFontMap *default_font_map = NULL; /* MT-safe */
PangoFontMap *
pango_cairo_font_map_get_default (void)
{
- if (g_once_init_enter ((gsize*)&default_font_map))
- g_once_init_leave((gsize*)&default_font_map, (gsize)pango_cairo_font_map_new ());
+ PangoFontMap *fontmap = g_private_get (&default_font_map);
- return default_font_map;
+ if (G_UNLIKELY (!fontmap))
+ {
+ fontmap = pango_cairo_font_map_new ();
+ g_private_replace (&default_font_map, fontmap);
+ }
+
+ return fontmap;
}
/**
@@ -174,21 +173,9 @@ pango_cairo_font_map_get_default (void)
void
pango_cairo_font_map_set_default (PangoCairoFontMap *fontmap)
{
- PangoCairoFontMap *def;
-
g_return_if_fail (fontmap == NULL || PANGO_IS_CAIRO_FONT_MAP (fontmap));
-retry:
- def = g_atomic_pointer_get (&default_font_map);
-
- if (!g_atomic_pointer_compare_and_exchange (&default_font_map, def, fontmap))
- goto retry;
-
- if (fontmap)
- g_object_ref (fontmap);
-
- if (def)
- g_object_unref (def);
+ g_private_replace (&default_font_map, g_object_ref (fontmap));
}
/**