From 80d76bb3d4ebf1101a8fe895459cce0a8369cd9f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 23 Jun 2011 13:36:25 +0100 Subject: [PATCH 4/8] DBusConnection: use atomic accesses to refcount, even for assertions --- dbus/dbus-connection.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 8849b1c..d80604a 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -1318,8 +1318,9 @@ _dbus_connection_new_for_transport (DBusTransport *transport) if (_dbus_modify_sigpipe) _dbus_disable_sigpipe (); - - connection->refcount.value = 1; + + /* initialized to 0: use atomic op to avoid mixing atomic and non-atomic */ + _dbus_atomic_inc (&connection->refcount); connection->transport = transport; connection->watches = watch_list; connection->timeouts = timeout_list; @@ -2661,11 +2662,16 @@ static void _dbus_connection_last_unref (DBusConnection *connection) { DBusList *link; + dbus_int32_t old_refcount; _dbus_verbose ("Finalizing connection %p\n", connection); - - _dbus_assert (connection->refcount.value == 0); - + +#ifndef DBUS_DISABLE_ASSERT + old_refcount = _dbus_atomic_inc (&connection->refcount); + _dbus_atomic_dec (&connection->refcount); + _dbus_assert (old_refcount == 0); +#endif + /* You have to disconnect the connection before unref:ing it. Otherwise * you won't get the disconnected message. */ -- 1.7.5.4