summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-04-16 16:52:20 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-06-17 17:10:02 +0100
commitd331e9c3e5c6a2ccac32c95bc973ba51048a63e3 (patch)
tree778c5648e9a5453438cad4066892e35bc88685f5
parent03703e8d9a1cecc35e0e8fc890dc61c0bd4f516f (diff)
[untested] add an automatically-initialized implementation of _dbus_lock on Windows54972-thread-safe5
-rw-r--r--dbus/dbus-sysdeps-thread-win.c28
-rw-r--r--dbus/dbus-threads.c8
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 */