diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2012-08-27 23:31:02 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2012-08-27 23:31:02 -0400 |
commit | f160843b9afab5d8f39654580d7583cf49b0c242 (patch) | |
tree | c3689b4082e3b36f66db86a937b6e9a51319c638 /pango | |
parent | a4eeee8e222db740ca83d29217d707db1160ada8 (diff) | |
download | pango-f160843b9afab5d8f39654580d7583cf49b0c242.tar.gz |
More thread-safety
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-context.c | 2 | ||||
-rw-r--r-- | pango/pango-engine.c | 2 | ||||
-rw-r--r-- | pango/pangocairo-fcfont.c | 2 | ||||
-rw-r--r-- | pango/pangocairo-fontmap.c | 16 | ||||
-rw-r--r-- | 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 cdb6a53a..97cb2786 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 eb75dd0b..7b2c2fd6 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 6e4fcd91..ee826756 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 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); } /** diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index 4f053c97..8315b6b3 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; } |