diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-07-14 17:20:21 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-07-26 17:42:16 +0100 |
commit | 438595294c544abd669d657bcc828e51f6868a39 (patch) | |
tree | 0c7cc8cb341afc445a1fb5edc6a46099f8959913 /dbus | |
parent | ef0f6ec93550560992b516ab1ae0ac30c0e2d8e6 (diff) | |
download | dbus-438595294c544abd669d657bcc828e51f6868a39.tar.gz |
DBusMessage: always access refcount atomically, even for assertions/initial ref
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38005
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-message.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index a6426ba4..a95ad0fa 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -526,7 +526,8 @@ dbus_message_get_cached (void) _dbus_assert (i < MAX_MESSAGE_CACHE_SIZE); _dbus_assert (message != NULL); - _dbus_assert (message->refcount.value == 0); + _dbus_assert (_dbus_atomic_get (&message->refcount) == 0); + _dbus_assert (message->counters == NULL); _DBUS_UNLOCK (message_cache); @@ -586,8 +587,8 @@ dbus_message_cache_or_finalize (DBusMessage *message) { dbus_bool_t was_cached; int i; - - _dbus_assert (message->refcount.value == 0); + + _dbus_assert (_dbus_atomic_get (&message->refcount) == 0); /* This calls application code and has to be done first thing * without holding the lock @@ -649,8 +650,8 @@ dbus_message_cache_or_finalize (DBusMessage *message) #endif out: - _dbus_assert (message->refcount.value == 0); - + _dbus_assert (_dbus_atomic_get (&message->refcount) == 0); + _DBUS_UNLOCK (message_cache); if (!was_cached) @@ -1039,7 +1040,7 @@ dbus_message_get_reply_serial (DBusMessage *message) static void dbus_message_finalize (DBusMessage *message) { - _dbus_assert (message->refcount.value == 0); + _dbus_assert (_dbus_atomic_get (&message->refcount) == 0); /* This calls application callbacks! */ _dbus_data_slot_list_free (&message->slot_list); @@ -1056,8 +1057,8 @@ dbus_message_finalize (DBusMessage *message) dbus_free(message->unix_fds); #endif - _dbus_assert (message->refcount.value == 0); - + _dbus_assert (_dbus_atomic_get (&message->refcount) == 0); + dbus_free (message); } @@ -1076,7 +1077,7 @@ dbus_message_new_empty_header (void) else { from_cache = FALSE; - message = dbus_new (DBusMessage, 1); + message = dbus_new0 (DBusMessage, 1); if (message == NULL) return NULL; #ifndef DBUS_DISABLE_CHECKS @@ -1088,8 +1089,9 @@ dbus_message_new_empty_header (void) message->n_unix_fds_allocated = 0; #endif } - - message->refcount.value = 1; + + _dbus_atomic_inc (&message->refcount); + message->byte_order = DBUS_COMPILER_BYTE_ORDER; message->locked = FALSE; #ifndef DBUS_DISABLE_CHECKS @@ -1448,7 +1450,7 @@ dbus_message_copy (const DBusMessage *message) if (retval == NULL) return NULL; - retval->refcount.value = 1; + _dbus_atomic_inc (&retval->refcount); retval->byte_order = message->byte_order; retval->locked = FALSE; #ifndef DBUS_DISABLE_CHECKS |