summaryrefslogtreecommitdiff
path: root/dbus/dbus-connection.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-26 11:51:13 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-26 11:51:13 +0100
commit0a6e7cb982d6ed5e3d4b3ecb8be21588b93487cc (patch)
tree2f559c7376343681d84b486d0178425812cd01a5 /dbus/dbus-connection.c
parentfeb31a33219bc0640c00138c14774995ab1a65a8 (diff)
parentb0f3874970845b9e598c6ffc3bb932620a3a0c33 (diff)
downloaddbus-0a6e7cb982d6ed5e3d4b3ecb8be21588b93487cc.tar.gz
Merge branch 'dbus-1.4'
Diffstat (limited to 'dbus/dbus-connection.c')
-rw-r--r--dbus/dbus-connection.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index bf927ba2..1417b733 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -342,8 +342,14 @@ static dbus_bool_t _dbus_connection_peek_for_reply_unlocked (DB
static DBusMessageFilter *
_dbus_message_filter_ref (DBusMessageFilter *filter)
{
- _dbus_assert (filter->refcount.value > 0);
+#ifdef DBUS_DISABLE_ASSERT
_dbus_atomic_inc (&filter->refcount);
+#else
+ dbus_int32_t old_value;
+
+ old_value = _dbus_atomic_inc (&filter->refcount);
+ _dbus_assert (old_value > 0);
+#endif
return filter;
}
@@ -351,9 +357,12 @@ _dbus_message_filter_ref (DBusMessageFilter *filter)
static void
_dbus_message_filter_unref (DBusMessageFilter *filter)
{
- _dbus_assert (filter->refcount.value > 0);
+ dbus_int32_t old_value;
+
+ old_value = _dbus_atomic_dec (&filter->refcount);
+ _dbus_assert (old_value > 0);
- if (_dbus_atomic_dec (&filter->refcount) == 1)
+ if (old_value == 1)
{
if (filter->free_user_data_function)
(* filter->free_user_data_function) (filter->user_data);
@@ -1310,8 +1319,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;
@@ -2108,23 +2118,15 @@ _dbus_connection_send_and_unlock (DBusConnection *connection,
void
_dbus_connection_close_if_only_one_ref (DBusConnection *connection)
{
- dbus_int32_t tmp_refcount;
+ dbus_int32_t refcount;
CONNECTION_LOCK (connection);
- /* We increment and then decrement the refcount, because there is no
- * _dbus_atomic_get (mirroring the fact that there's no InterlockedGet
- * on Windows). */
- _dbus_atomic_inc (&connection->refcount);
- tmp_refcount = _dbus_atomic_dec (&connection->refcount);
-
- /* The caller should have one ref, and this function temporarily took
- * one more, which is reflected in this count even though we already
- * released it (relying on the caller's ref) due to _dbus_atomic_dec
- * semantics */
- _dbus_assert (tmp_refcount >= 2);
+ refcount = _dbus_atomic_get (&connection->refcount);
+ /* The caller should have at least one ref */
+ _dbus_assert (refcount >= 1);
- if (tmp_refcount == 2)
+ if (refcount == 1)
_dbus_connection_close_possibly_shared_and_unlock (connection);
else
CONNECTION_UNLOCK (connection);
@@ -2655,9 +2657,9 @@ _dbus_connection_last_unref (DBusConnection *connection)
DBusList *link;
_dbus_verbose ("Finalizing connection %p\n", connection);
-
- _dbus_assert (connection->refcount.value == 0);
-
+
+ _dbus_assert (_dbus_atomic_get (&connection->refcount) == 0);
+
/* You have to disconnect the connection before unref:ing it. Otherwise
* you won't get the disconnected message.
*/
@@ -5420,8 +5422,8 @@ dbus_connection_add_filter (DBusConnection *connection,
if (filter == NULL)
return FALSE;
- filter->refcount.value = 1;
-
+ _dbus_atomic_inc (&filter->refcount);
+
CONNECTION_LOCK (connection);
if (!_dbus_list_append (&connection->filter_list,