diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-14 18:38:48 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-21 14:41:28 +0000 |
commit | f85ca5fac1317e44b87c5ca4e3d670e505001db8 (patch) | |
tree | 082a5b2359225eb168bbfd36d512a7f36ae878ff /dbus | |
parent | 8a58250acfeffc4e311169903f9e782fcad79547 (diff) | |
download | dbus-f85ca5fac1317e44b87c5ca4e3d670e505001db8.tar.gz |
Allow both recursive and non-recursive mutexes to be supplied
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=43744
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Thiago Macieira <thiago@kde.org>
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-threads.c | 19 | ||||
-rw-r--r-- | dbus/dbus-threads.h | 23 |
2 files changed, 17 insertions, 25 deletions
diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c index eff30542..81308477 100644 --- a/dbus/dbus-threads.c +++ b/dbus/dbus-threads.c @@ -734,13 +734,6 @@ dbus_threads_init (const DBusThreadFunctions *functions) "functions sets should be passed into " "dbus_threads_init. Neither sets were passed."); - if (mutex_set && recursive_mutex_set) - _dbus_assert_not_reached ("Either the nonrecusrive or recursive mutex " - "functions sets should be passed into " - "dbus_threads_init. Both sets were passed. " - "You most likely just want to set the recursive " - "mutex functions to avoid deadlocks in D-Bus."); - /* Check that all bits in the mask actually are valid mask bits. * ensures people won't write code that breaks when we add * new bits. @@ -770,15 +763,23 @@ dbus_threads_init (const DBusThreadFunctions *functions) if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK) thread_functions.recursive_mutex_new = functions->recursive_mutex_new; - + else + thread_functions.recursive_mutex_new = NULL; + if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK) thread_functions.recursive_mutex_free = functions->recursive_mutex_free; - + else + thread_functions.recursive_mutex_free = NULL; + if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK) thread_functions.recursive_mutex_lock = functions->recursive_mutex_lock; + else + thread_functions.recursive_mutex_lock = NULL; if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK) thread_functions.recursive_mutex_unlock = functions->recursive_mutex_unlock; + else + thread_functions.recursive_mutex_unlock = NULL; thread_functions.mask = functions->mask; diff --git a/dbus/dbus-threads.h b/dbus/dbus-threads.h index ba07ca57..6d28a0b6 100644 --- a/dbus/dbus-threads.h +++ b/dbus/dbus-threads.h @@ -139,24 +139,15 @@ typedef enum /** * Functions that must be implemented to make the D-Bus library - * thread-aware. The recursive mutex functions should be specified - * rather than the old, deprecated nonrecursive ones. + * thread-aware. * - * The condition variable functions have to work with recursive - * mutexes if you provide those, or with nonrecursive mutexes if you - * provide those. + * If you supply both recursive and non-recursive mutexes, + * libdbus will use the non-recursive version for condition variables, + * and the recursive version in other contexts. * - * If implementing threads using pthreads, be aware that - * PTHREAD_MUTEX_RECURSIVE is broken in combination with condition - * variables. libdbus relies on the Java-style behavior that when - * waiting on a condition, the recursion count is saved and restored, - * and the mutex is completely unlocked, not just decremented one - * level of recursion. - * - * Thus with pthreads you probably have to roll your own emulated - * recursive mutexes, you can't use PTHREAD_MUTEX_RECURSIVE. This is - * what dbus_threads_init_default() does on platforms that use - * pthreads. + * The condition variable functions have to work with nonrecursive + * mutexes if you provide those, or with recursive mutexes if you + * don't. */ typedef struct { |