From e7f1f1aab760b87327bd9c35df7c5e3d1d735ac7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 27 Aug 2012 22:53:49 -0400 Subject: Make pango-attributes thread-safe --- pango/pango-attributes.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'pango/pango-attributes.c') diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index e76cb71d..778a2823 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -54,7 +54,8 @@ static PangoAttribute *pango_attr_size_new_internal (int size, gboolean absolute); -static GHashTable *name_map = NULL; +G_LOCK_DEFINE_STATIC (attr_type); +static GHashTable *name_map = NULL; /* MT-safe */ /** * pango_attr_type_register: @@ -68,7 +69,10 @@ static GHashTable *name_map = NULL; PangoAttrType pango_attr_type_register (const gchar *name) { - static guint current_type = 0x1000000; + static guint current_type = 0x1000000; /* MT-safe */ + + G_LOCK (attr_type); + guint type = current_type++; if (name) @@ -79,6 +83,8 @@ pango_attr_type_register (const gchar *name) g_hash_table_insert (name_map, GUINT_TO_POINTER (type), (gpointer) g_intern_string (name)); } + G_UNLOCK (attr_type); + return type; } @@ -102,9 +108,13 @@ pango_attr_type_get_name (PangoAttrType type) { const char *result = NULL; + G_LOCK (attr_type); + if (name_map) result = g_hash_table_lookup (name_map, GUINT_TO_POINTER ((guint) type)); + G_UNLOCK (attr_type); + return result; } -- cgit v1.2.1