diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2021-12-20 11:52:45 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2022-05-01 18:55:05 +0200 |
commit | 72a7758e38be9b7b373155e39ee72b5ab1db9567 (patch) | |
tree | a7fb6236d35f31b105326666ae9c7a7eedcbb156 /dbus | |
parent | 31307769ca4c37aca5c589d9a1f32218570006db (diff) | |
download | dbus-72a7758e38be9b7b373155e39ee72b5ab1db9567.tar.gz |
Add assertions to the [c|r]mutex related functions on Windows
This detects some error conditions that can only occur as a
result of a programming error, such as attempting to unlock a
mutex that is not locked.
Fixes #369
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-sysdeps-thread-win.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c index 3b600fa9..ca4a3db5 100644 --- a/dbus/dbus-sysdeps-thread-win.c +++ b/dbus/dbus-sysdeps-thread-win.c @@ -32,6 +32,18 @@ #include <windows.h> +#ifdef DBUS_DISABLE_ASSERT +#define THREAD_CHECK_TRUE(func_name, result_or_call) \ + do { if (!(result_or_call)) { /* ignore */ } } while (0) +#else +#define THREAD_CHECK_TRUE(func_name, result_or_call) do { \ + if (!(result_or_call)) { \ + _dbus_warn_check_failed ("thread function %s failed (windows error code=%ld) in %s", \ + func_name, GetLastError (), _DBUS_FUNCTION_NAME); \ + } \ +} while (0) +#endif /* !DBUS_DISABLE_ASSERT */ + /* Protected by DllMain lock, effectively */ static dbus_bool_t global_init_done = FALSE; static CRITICAL_SECTION init_lock; @@ -113,6 +125,7 @@ _dbus_platform_cmutex_new (void) { HANDLE handle; handle = CreateMutex (NULL, FALSE, NULL); + THREAD_CHECK_TRUE ("CreateMutex", handle); return (DBusCMutex *) handle; } @@ -121,43 +134,44 @@ _dbus_platform_rmutex_new (void) { HANDLE handle; handle = CreateMutex (NULL, FALSE, NULL); + THREAD_CHECK_TRUE ("CreateMutex", handle); return (DBusRMutex *) handle; } void _dbus_platform_cmutex_free (DBusCMutex *mutex) { - CloseHandle ((HANDLE *) mutex); + THREAD_CHECK_TRUE ("CloseHandle", CloseHandle ((HANDLE *) mutex)); } void _dbus_platform_rmutex_free (DBusRMutex *mutex) { - CloseHandle ((HANDLE *) mutex); + THREAD_CHECK_TRUE ("CloseHandle", CloseHandle ((HANDLE *) mutex)); } void _dbus_platform_cmutex_lock (DBusCMutex *mutex) { - WaitForSingleObject ((HANDLE *) mutex, INFINITE); + THREAD_CHECK_TRUE ("WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0); } void _dbus_platform_rmutex_lock (DBusRMutex *mutex) { - WaitForSingleObject ((HANDLE *) mutex, INFINITE); + THREAD_CHECK_TRUE ("WaitForSingleObject", WaitForSingleObject ((HANDLE *) mutex, INFINITE) == WAIT_OBJECT_0); } void _dbus_platform_cmutex_unlock (DBusCMutex *mutex) { - ReleaseMutex ((HANDLE *) mutex); + THREAD_CHECK_TRUE ("ReleaseMutex", ReleaseMutex ((HANDLE *) mutex)); } void _dbus_platform_rmutex_unlock (DBusRMutex *mutex) { - ReleaseMutex ((HANDLE *) mutex); + THREAD_CHECK_TRUE ("ReleaseMutex", ReleaseMutex ((HANDLE *) mutex)); } DBusCondVar * |