[pango] More thread-safety
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] More thread-safety
- Date: Tue, 28 Aug 2012 04:34:07 +0000 (UTC)
commit f160843b9afab5d8f39654580d7583cf49b0c242
Author: Behdad Esfahbod <behdad behdad org>
Date: Mon Aug 27 23:31:02 2012 -0400
More thread-safety
pango/pango-context.c | 2 +-
pango/pango-engine.c | 2 +-
pango/pangocairo-fcfont.c | 2 +-
pango/pangocairo-fontmap.c | 16 ++++++++++------
pango/pangofc-fontmap.c | 6 +++---
5 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/pango/pango-context.c b/pango/pango-context.c
index cdb6a53..97cb278 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -1366,7 +1366,7 @@ itemize_state_update_for_new_run (ItemizeState *state)
static const char *
string_from_script (PangoScript script)
{
- static GEnumClass *class = NULL;
+ static GEnumClass *class = NULL; /* MT-safe */
GEnumValue *value;
if (g_once_init_enter ((gsize*)&class))
g_once_init_leave((gsize*)&class, (gsize)g_type_class_ref (PANGO_TYPE_SCRIPT));
diff --git a/pango/pango-engine.c b/pango/pango-engine.c
index eb75dd0..7b2c2fd 100644
--- a/pango/pango-engine.c
+++ b/pango/pango-engine.c
@@ -197,7 +197,7 @@ pango_fallback_engine_class_init (PangoFallbackEngineClass *class)
PangoEngineShape *
_pango_get_fallback_shaper (void)
{
- static PangoEngineShape *fallback_shaper = NULL;
+ static PangoEngineShape *fallback_shaper = NULL; /* MT-safe */
if (g_once_init_enter ((gsize*)&fallback_shaper))
g_once_init_leave((gsize*)&fallback_shaper, (gsize)g_object_new (pango_fallback_engine_get_type (), NULL));
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 6e4fcd9..ee82675 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -185,7 +185,7 @@ get_font_size (const FcPattern *pattern)
static gpointer
get_gravity_class (void)
{
- static GEnumClass *class = NULL;
+ static GEnumClass *class = NULL; /* MT-safe */
if (g_once_init_enter ((gsize*)&class))
g_once_init_leave((gsize*)&class, (gsize)g_type_class_ref (PANGO_TYPE_GRAVITY));
diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c
index cfc658f..1c235ac 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);
}
/**
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 4f053c9..8315b6b 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -235,10 +235,10 @@ static FcPattern *uniquify_pattern (PangoFcFontMap *fcfontmap,
static gpointer
get_gravity_class (void)
{
- static GEnumClass *class = NULL;
+ static GEnumClass *class = NULL; /* MT-safe */
- if (G_UNLIKELY (!class))
- class = g_type_class_ref (PANGO_TYPE_GRAVITY);
+ if (g_once_init_enter ((gsize*)&class))
+ g_once_init_leave ((gsize*)&class, (gsize)g_type_class_ref (PANGO_TYPE_GRAVITY));
return class;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]