diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-04-16 12:07:23 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-05-10 11:35:08 +0100 |
commit | 17a23d08b51cf21a2110047649a86445e99e2b3f (patch) | |
tree | 127ee33f09bab2955a07fd22e81781f0f79a2720 /dbus/dbus-sysdeps-thread-win.c | |
parent | 863c989bb631d7063597db30fe8add3233cca7fd (diff) | |
download | dbus-17a23d08b51cf21a2110047649a86445e99e2b3f.tar.gz |
dbus_threads_init_default, dbus_threads_init: be safe to call at any time
On Unix, we use a pthreads mutex, which can be allocated and
initialized in global memory.
On Windows, we use a CRITICAL_SECTION, together with a call to
InitializeCriticalSection() from the constructor of a global static
C++ object (thanks to Ralf Habacker for suggesting this approach).
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Diffstat (limited to 'dbus/dbus-sysdeps-thread-win.c')
-rw-r--r-- | dbus/dbus-sysdeps-thread-win.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c index 4c4442a6..0887a549 100644 --- a/dbus/dbus-sysdeps-thread-win.c +++ b/dbus/dbus-sysdeps-thread-win.c @@ -30,6 +30,21 @@ #include <windows.h> +static dbus_bool_t global_init_done = FALSE; +static CRITICAL_SECTION init_lock; + +/* Called from C++ code in dbus-init-win.cpp. */ +void +_dbus_threads_windows_init_global (void) +{ + /* this ensures that the object that acts as our global constructor + * actually gets linked in when we're linked statically */ + _dbus_threads_windows_ensure_ctor_linked (); + + InitializeCriticalSection (&init_lock); + global_init_done = TRUE; +} + struct DBusCondVar { DBusList *list; /**< list thread-local-stored events waiting on the cond variable */ CRITICAL_SECTION lock; /**< lock protecting the list */ @@ -272,3 +287,16 @@ _dbus_threads_init_platform_specific (void) return TRUE; } +void +_dbus_threads_lock_platform_specific (void) +{ + _dbus_assert (global_init_done); + EnterCriticalSection (&init_lock); +} + +void +_dbus_threads_unlock_platform_specific (void) +{ + _dbus_assert (global_init_done); + LeaveCriticalSection (&init_lock); +} |