diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-03-26 18:06:53 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-03-26 18:06:53 +0000 |
commit | a0124a5ecc829b73e2293cd7b23bf0cf0eb0a87c (patch) | |
tree | 6bfa2f3f4d6ea18a0f5c314ef2686238c8d29cfd /dbus/dbus-gtype-specialized.c | |
parent | e18f5dd13c562333bc580f3b5bdf3ecd8d7555ce (diff) | |
download | dbus-glib-a0124a5ecc829b73e2293cd7b23bf0cf0eb0a87c.tar.gz |
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 <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'dbus/dbus-gtype-specialized.c')
-rw-r--r-- | 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 |