summaryrefslogtreecommitdiff
path: root/dbus/dbus-connection.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-14 19:58:56 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-21 14:41:25 +0000
commit8a58250acfeffc4e311169903f9e782fcad79547 (patch)
tree47360102b46407d931a9e4a9e1a55e13683b3f8b /dbus/dbus-connection.c
parent4d4da20ce7e4eebc6b4467d193cb7cec4cfeb17a (diff)
downloaddbus-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-connection.c')
-rw-r--r--dbus/dbus-connection.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index b8f48adf..74a9007c 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -66,18 +66,18 @@
#define CONNECTION_LOCK(connection) do { \
if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
- _dbus_mutex_lock ((connection)->mutex); \
+ _dbus_rmutex_lock ((connection)->mutex); \
TOOK_LOCK_CHECK (connection); \
} while (0)
#define CONNECTION_UNLOCK(connection) _dbus_connection_unlock (connection)
#define SLOTS_LOCK(connection) do { \
- _dbus_mutex_lock ((connection)->slot_mutex); \
+ _dbus_rmutex_lock ((connection)->slot_mutex); \
} while (0)
#define SLOTS_UNLOCK(connection) do { \
- _dbus_mutex_unlock ((connection)->slot_mutex); \
+ _dbus_rmutex_unlock ((connection)->slot_mutex); \
} while (0)
#define DISPATCH_STATUS_NAME(s) \
@@ -264,11 +264,11 @@ struct DBusConnection
{
DBusAtomic refcount; /**< Reference count. */
- DBusMutex *mutex; /**< Lock on the entire DBusConnection */
+ DBusRMutex *mutex; /**< Lock on the entire DBusConnection */
- DBusMutex *dispatch_mutex; /**< Protects dispatch_acquired */
+ DBusCMutex *dispatch_mutex; /**< Protects dispatch_acquired */
DBusCondVar *dispatch_cond; /**< Notify when dispatch_acquired is available */
- DBusMutex *io_path_mutex; /**< Protects io_path_acquired */
+ DBusCMutex *io_path_mutex; /**< Protects io_path_acquired */
DBusCondVar *io_path_cond; /**< Notify when io_path_acquired is available */
DBusList *outgoing_messages; /**< Queue of messages we need to send, send the end of the list first. */
@@ -290,7 +290,7 @@ struct DBusConnection
DBusList *filter_list; /**< List of filters. */
- DBusMutex *slot_mutex; /**< Lock on slot_list so overall connection lock need not be taken */
+ DBusRMutex *slot_mutex; /**< Lock on slot_list so overall connection lock need not be taken */
DBusDataSlotList slot_list; /**< Data stored by allocated integer ID */
DBusHashTable *pending_replies; /**< Hash of message serials to #DBusPendingCall. */
@@ -419,7 +419,7 @@ _dbus_connection_unlock (DBusConnection *connection)
connection->expired_messages = NULL;
RELEASING_LOCK_CHECK (connection);
- _dbus_mutex_unlock (connection->mutex);
+ _dbus_rmutex_unlock (connection->mutex);
for (iter = _dbus_list_pop_first_link (&expired_messages);
iter != NULL;
@@ -467,9 +467,9 @@ _dbus_connection_test_get_locks (DBusConnection *connection,
DBusCondVar **dispatch_cond_loc,
DBusCondVar **io_path_cond_loc)
{
- *mutex_loc = connection->mutex;
- *dispatch_mutex_loc = connection->dispatch_mutex;
- *io_path_mutex_loc = connection->io_path_mutex;
+ *mutex_loc = (DBusMutex *) connection->mutex;
+ *dispatch_mutex_loc = (DBusMutex *) connection->dispatch_mutex;
+ *io_path_mutex_loc = (DBusMutex *) connection->io_path_mutex;
*dispatch_cond_loc = connection->dispatch_cond;
*io_path_cond_loc = connection->io_path_cond;
}
@@ -1079,7 +1079,7 @@ _dbus_connection_acquire_io_path (DBusConnection *connection,
CONNECTION_UNLOCK (connection);
_dbus_verbose ("locking io_path_mutex\n");
- _dbus_mutex_lock (connection->io_path_mutex);
+ _dbus_cmutex_lock (connection->io_path_mutex);
_dbus_verbose ("start connection->io_path_acquired = %d timeout = %d\n",
connection->io_path_acquired, timeout_milliseconds);
@@ -1128,7 +1128,7 @@ _dbus_connection_acquire_io_path (DBusConnection *connection,
connection->io_path_acquired, we_acquired);
_dbus_verbose ("unlocking io_path_mutex\n");
- _dbus_mutex_unlock (connection->io_path_mutex);
+ _dbus_cmutex_unlock (connection->io_path_mutex);
CONNECTION_LOCK (connection);
@@ -1152,7 +1152,7 @@ _dbus_connection_release_io_path (DBusConnection *connection)
HAVE_LOCK_CHECK (connection);
_dbus_verbose ("locking io_path_mutex\n");
- _dbus_mutex_lock (connection->io_path_mutex);
+ _dbus_cmutex_lock (connection->io_path_mutex);
_dbus_assert (connection->io_path_acquired);
@@ -1163,7 +1163,7 @@ _dbus_connection_release_io_path (DBusConnection *connection)
_dbus_condvar_wake_one (connection->io_path_cond);
_dbus_verbose ("unlocking io_path_mutex\n");
- _dbus_mutex_unlock (connection->io_path_mutex);
+ _dbus_cmutex_unlock (connection->io_path_mutex);
}
/**
@@ -1292,15 +1292,15 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
if (connection == NULL)
goto error;
- _dbus_mutex_new_at_location (&connection->mutex);
+ _dbus_rmutex_new_at_location (&connection->mutex);
if (connection->mutex == NULL)
goto error;
- _dbus_mutex_new_at_location (&connection->io_path_mutex);
+ _dbus_cmutex_new_at_location (&connection->io_path_mutex);
if (connection->io_path_mutex == NULL)
goto error;
- _dbus_mutex_new_at_location (&connection->dispatch_mutex);
+ _dbus_cmutex_new_at_location (&connection->dispatch_mutex);
if (connection->dispatch_mutex == NULL)
goto error;
@@ -1312,7 +1312,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
if (connection->io_path_cond == NULL)
goto error;
- _dbus_mutex_new_at_location (&connection->slot_mutex);
+ _dbus_rmutex_new_at_location (&connection->slot_mutex);
if (connection->slot_mutex == NULL)
goto error;
@@ -1391,10 +1391,10 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
{
_dbus_condvar_free_at_location (&connection->io_path_cond);
_dbus_condvar_free_at_location (&connection->dispatch_cond);
- _dbus_mutex_free_at_location (&connection->mutex);
- _dbus_mutex_free_at_location (&connection->io_path_mutex);
- _dbus_mutex_free_at_location (&connection->dispatch_mutex);
- _dbus_mutex_free_at_location (&connection->slot_mutex);
+ _dbus_rmutex_free_at_location (&connection->mutex);
+ _dbus_cmutex_free_at_location (&connection->io_path_mutex);
+ _dbus_cmutex_free_at_location (&connection->dispatch_mutex);
+ _dbus_rmutex_free_at_location (&connection->slot_mutex);
dbus_free (connection);
}
if (pending_replies)
@@ -2739,12 +2739,12 @@ _dbus_connection_last_unref (DBusConnection *connection)
_dbus_condvar_free_at_location (&connection->dispatch_cond);
_dbus_condvar_free_at_location (&connection->io_path_cond);
- _dbus_mutex_free_at_location (&connection->io_path_mutex);
- _dbus_mutex_free_at_location (&connection->dispatch_mutex);
+ _dbus_cmutex_free_at_location (&connection->io_path_mutex);
+ _dbus_cmutex_free_at_location (&connection->dispatch_mutex);
- _dbus_mutex_free_at_location (&connection->slot_mutex);
+ _dbus_rmutex_free_at_location (&connection->slot_mutex);
- _dbus_mutex_free_at_location (&connection->mutex);
+ _dbus_rmutex_free_at_location (&connection->mutex);
dbus_free (connection);
}
@@ -4088,7 +4088,7 @@ _dbus_connection_acquire_dispatch (DBusConnection *connection)
CONNECTION_UNLOCK (connection);
_dbus_verbose ("locking dispatch_mutex\n");
- _dbus_mutex_lock (connection->dispatch_mutex);
+ _dbus_cmutex_lock (connection->dispatch_mutex);
while (connection->dispatch_acquired)
{
@@ -4102,7 +4102,7 @@ _dbus_connection_acquire_dispatch (DBusConnection *connection)
connection->dispatch_acquired = TRUE;
_dbus_verbose ("unlocking dispatch_mutex\n");
- _dbus_mutex_unlock (connection->dispatch_mutex);
+ _dbus_cmutex_unlock (connection->dispatch_mutex);
CONNECTION_LOCK (connection);
_dbus_connection_unref_unlocked (connection);
@@ -4121,7 +4121,7 @@ _dbus_connection_release_dispatch (DBusConnection *connection)
HAVE_LOCK_CHECK (connection);
_dbus_verbose ("locking dispatch_mutex\n");
- _dbus_mutex_lock (connection->dispatch_mutex);
+ _dbus_cmutex_lock (connection->dispatch_mutex);
_dbus_assert (connection->dispatch_acquired);
@@ -4129,7 +4129,7 @@ _dbus_connection_release_dispatch (DBusConnection *connection)
_dbus_condvar_wake_one (connection->dispatch_cond);
_dbus_verbose ("unlocking dispatch_mutex\n");
- _dbus_mutex_unlock (connection->dispatch_mutex);
+ _dbus_cmutex_unlock (connection->dispatch_mutex);
}
static void