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)
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)
}
}
-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:
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;
}
/**
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));
}
/**