From a0124a5ecc829b73e2293cd7b23bf0cf0eb0a87c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 26 Mar 2009 18:06:53 +0000 Subject: [PATCH 2/3] dbus_g_type_specialized_init: make some effort at being thread-safe dbus-glib isn't really thread-safe and needs a systematic audit, but let's at least be preemptively thread-safe in new code. Signed-off-by: Simon McVittie --- dbus/dbus-gtype-specialized.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dbus/dbus-gtype-specialized.c b/dbus/dbus-gtype-specialized.c index a7968dc..220f603 100644 --- a/dbus/dbus-gtype-specialized.c +++ b/dbus/dbus-gtype-specialized.c @@ -87,15 +87,24 @@ specialized_type_data_quark () return quark; } +static gpointer +specialized_init (gpointer arg G_GNUC_UNUSED) +{ + g_assert (specialized_containers == NULL); + + specialized_containers = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + + _dbus_g_type_specialized_builtins_init (); + return NULL; +} + void dbus_g_type_specialized_init (void) { - if (specialized_containers) - return; - - specialized_containers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - - _dbus_g_type_specialized_builtins_init (); + static GOnce once = G_ONCE_INIT; + + g_once (&once, specialized_init, NULL); } static gboolean -- 1.6.3.1