diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-14 19:58:56 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-21 14:41:25 +0000 |
commit | 8a58250acfeffc4e311169903f9e782fcad79547 (patch) | |
tree | 47360102b46407d931a9e4a9e1a55e13683b3f8b /dbus/dbus-threads-internal.h | |
parent | 4d4da20ce7e4eebc6b4467d193cb7cec4cfeb17a (diff) | |
download | dbus-8a58250acfeffc4e311169903f9e782fcad79547.tar.gz |
Distinguish between two flavours of mutex
dbus-threads.h warns that recursive pthreads mutexes are not compatible
with our expectations for condition variables. However, the only two
condition variables we actually use only have their corresponding
mutexes locked briefly (and we don't call out to user code from there),
so the mutexes don't need to be recursive anyway. That's just as well,
because it turns out our implementation of recursive mutexes on
pthreads is broken!
The goal here is to be able to distinguish between "cmutexes" (mutexes
compatible with a condition variable) and "rmutexes" (mutexes which
are recursive if possible, to avoid deadlocking if we hold them while
calling user code).
This is complicated by the fact that callers are not guaranteed to have
provided us with both versions of mutexes, so we might have to implement
one by using the other (in particular, DBusRMutex *aims to be*
recursive, it is not *guaranteed to be* recursive).
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/dbus-threads-internal.h')
-rw-r--r-- | dbus/dbus-threads-internal.h | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/dbus/dbus-threads-internal.h b/dbus/dbus-threads-internal.h index 68aa20af..2561136d 100644 --- a/dbus/dbus-threads-internal.h +++ b/dbus/dbus-threads-internal.h @@ -27,19 +27,43 @@ #include <dbus/dbus-types.h> #include <dbus/dbus-threads.h> +/** + * @addtogroup DBusThreadsInternals + * @{ + */ + +/** + * A mutex which is recursive if possible, else non-recursive. + * This is typically recursive, but that cannot be relied upon. + */ +typedef struct DBusRMutex DBusRMutex; + +/** + * A mutex suitable for use with condition variables. + * This is typically non-recursive. + */ +typedef struct DBusCMutex DBusCMutex; + +/** @} */ + DBUS_BEGIN_DECLS -void _dbus_mutex_lock (DBusMutex *mutex); -void _dbus_mutex_unlock (DBusMutex *mutex); -void _dbus_mutex_new_at_location (DBusMutex **location_p); -void _dbus_mutex_free_at_location (DBusMutex **location_p); +void _dbus_rmutex_lock (DBusRMutex *mutex); +void _dbus_rmutex_unlock (DBusRMutex *mutex); +void _dbus_rmutex_new_at_location (DBusRMutex **location_p); +void _dbus_rmutex_free_at_location (DBusRMutex **location_p); + +void _dbus_cmutex_lock (DBusCMutex *mutex); +void _dbus_cmutex_unlock (DBusCMutex *mutex); +void _dbus_cmutex_new_at_location (DBusCMutex **location_p); +void _dbus_cmutex_free_at_location (DBusCMutex **location_p); DBusCondVar* _dbus_condvar_new (void); void _dbus_condvar_free (DBusCondVar *cond); void _dbus_condvar_wait (DBusCondVar *cond, - DBusMutex *mutex); + DBusCMutex *mutex); dbus_bool_t _dbus_condvar_wait_timeout (DBusCondVar *cond, - DBusMutex *mutex, + DBusCMutex *mutex, int timeout_milliseconds); void _dbus_condvar_wake_one (DBusCondVar *cond); void _dbus_condvar_wake_all (DBusCondVar *cond); |