summaryrefslogtreecommitdiff
path: root/pango/pangocairo-fontmap.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2012-08-27 23:31:02 -0400
committerBehdad Esfahbod <behdad@behdad.org>2012-08-27 23:31:02 -0400
commitf160843b9afab5d8f39654580d7583cf49b0c242 (patch)
treec3689b4082e3b36f66db86a937b6e9a51319c638 /pango/pangocairo-fontmap.c
parenta4eeee8e222db740ca83d29217d707db1160ada8 (diff)
downloadpango-f160843b9afab5d8f39654580d7583cf49b0c242.tar.gz
More thread-safety
Diffstat (limited to 'pango/pangocairo-fontmap.c')
-rw-r--r--pango/pangocairo-fontmap.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c
index cfc658f0..1c235acb 100644
--- a/pango/pangocairo-fontmap.c
+++ b/pango/pangocairo-fontmap.c
@@ -124,7 +124,7 @@ pango_cairo_font_map_new_for_font_type (cairo_font_type_t fonttype)
}
}
-static PangoFontMap *default_font_map = NULL;
+static PangoFontMap *default_font_map = NULL; /* MT-safe */
/**
* pango_cairo_font_map_get_default:
@@ -174,17 +174,21 @@ 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));
- if ((PangoFontMap *) fontmap == default_font_map)
- return;
+retry:
+ def = g_atomic_pointer_get (&default_font_map);
- if (default_font_map)
- g_object_unref (default_font_map);
+ if (!g_atomic_pointer_compare_and_exchange (&default_font_map, def, fontmap))
+ goto retry;
if (fontmap)
g_object_ref (fontmap);
- default_font_map = (PangoFontMap *) fontmap;
+
+ if (def)
+ g_object_unref (def);
}
/**