summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2012-08-27 22:53:49 -0400
committerBehdad Esfahbod <behdad@behdad.org>2012-08-27 22:55:34 -0400
commite7f1f1aab760b87327bd9c35df7c5e3d1d735ac7 (patch)
tree833c2524a2487c07e8873ee30b648056b440a841
parent476cba0d2af65b57b297044f26139b493796494a (diff)
downloadpango-e7f1f1aab760b87327bd9c35df7c5e3d1d735ac7.tar.gz
Make pango-attributes thread-safe
-rw-r--r--pango/pango-attributes.c14
1 files changed, 12 insertions, 2 deletions
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;
}