From 2e42a7bdd3d643e177528ca3c48f74c003b9e942 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 16 Apr 2013 16:52:20 +0100 Subject: [PATCH 11/11] [untested] add an automatically-initialized implementation of _dbus_lock on Windows --- dbus/dbus-sysdeps-thread-win.c | 28 ++++++++++++++++++++++++++++ dbus/dbus-threads.c | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c index 0887a54..49b8a1b 100644 --- a/dbus/dbus-sysdeps-thread-win.c +++ b/dbus/dbus-sysdeps-thread-win.c @@ -32,16 +32,23 @@ static dbus_bool_t global_init_done = FALSE; static CRITICAL_SECTION init_lock; +static CRITICAL_SECTION global_locks[_DBUS_N_GLOBAL_LOCKS]; /* Called from C++ code in dbus-init-win.cpp. */ void _dbus_threads_windows_init_global (void) { + int i; + /* 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); + + for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++) + InitializeCriticalSection (&(global_locks[i])); + global_init_done = TRUE; } @@ -300,3 +307,24 @@ _dbus_threads_unlock_platform_specific (void) _dbus_assert (global_init_done); LeaveCriticalSection (&init_lock); } + +dbus_bool_t +_dbus_lock (DBusGlobalLock lock) +{ + _dbus_assert (global_init_done); + _dbus_assert (lock >= 0); + _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS); + + EnterCriticalSection (&(global_locks[lock])); + return TRUE; +} + +void +_dbus_unlock (DBusGlobalLock lock) +{ + _dbus_assert (global_init_done); + _dbus_assert (lock >= 0); + _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS); + + LeaveCriticalSection (&(global_locks[lock])); +} diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c index 1781bda..06ad166 100644 --- a/dbus/dbus-threads.c +++ b/dbus/dbus-threads.c @@ -283,7 +283,7 @@ _dbus_condvar_wake_one (DBusCondVar *cond) _dbus_platform_condvar_wake_one (cond); } -#ifdef DBUS_HAVE_STATIC_RECURSIVE_MUTEXES +#if defined(DBUS_HAVE_STATIC_RECURSIVE_MUTEXES) || defined(DBUS_WIN) static dbus_bool_t init_global_locks (void) @@ -291,9 +291,9 @@ init_global_locks (void) return TRUE; } -/* implementations in dbus-sysdeps-pthread.c */ +/* implementations in dbus-sysdeps-pthread.c or dbus-sysdeps-thread-win.c */ -#else /* !defined(DBUS_HAVE_STATIC_RECURSIVE_MUTEXES) */ +#else /* !defined(DBUS_HAVE_STATIC_RECURSIVE_MUTEXES) && !defined(DBUS_WIN) */ static DBusRMutex *global_locks[_DBUS_N_GLOBAL_LOCKS] = { NULL }; @@ -368,7 +368,7 @@ _dbus_unlock (DBusGlobalLock lock) _dbus_platform_rmutex_unlock (global_locks[lock]); } -#endif /* !defined(DBUS_HAVE_STATIC_RECURSIVE_MUTEXES) */ +#endif /* !defined(DBUS_HAVE_STATIC_RECURSIVE_MUTEXES) && !defined(DBUS_WIN) */ /** @} */ /* end of internals */ -- 1.7.10.4