diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-04-16 16:52:20 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-05-08 17:02:32 +0100 |
commit | 7fd0ffb22d7659b56fb324c08c1f60897bfba4c2 (patch) | |
tree | 008cbfa960fa3adc611d7cf81b64f19255ff013f | |
parent | 46cd657eee1d6cb13ccbb2a69d00c62f7d05dcca (diff) |
[untested] add an automatically-initialized implementation of _dbus_lock on Windowsthread-safe4
-rw-r--r-- | dbus/dbus-sysdeps-thread-win.c | 28 | ||||
-rw-r--r-- | 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 0887a549..49b8a1b0 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 1781bdaf..06ad1661 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 */ |