From e6b4bc6dde76c8c816e0e430a71095c6734c766c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 19 Sep 2011 15:57:02 +0100 Subject: [PATCH 5/8] Add and use _dbus_message_trace_ref --- dbus/dbus-connection.c | 23 +++++++++++++++++++++-- dbus/dbus-message-internal.h | 15 +++++++++++++++ dbus/dbus-message.c | 26 ++++++++++++++++++++------ dbus/dbus-pending-call.c | 4 +++- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index cb1da8c..9123d8b 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -539,7 +539,11 @@ _dbus_connection_queue_received_message_link (DBusConnection *connection, dbus_message_get_signature (message), dbus_message_get_reply_serial (message), connection, - connection->n_incoming);} + connection->n_incoming); + + _dbus_message_trace_ref (message, -1, -1, + "_dbus_conection_queue_received_message_link"); +} /** * Adds a link + message to the incoming message queue. @@ -560,7 +564,10 @@ _dbus_connection_queue_synthesized_message_link (DBusConnection *connection, connection->n_incoming += 1; _dbus_connection_wakeup_mainloop (connection); - + + _dbus_message_trace_ref (link->data, -1, -1, + "_dbus_connection_queue_synthesized_message_link"); + _dbus_verbose ("Synthesized message %p added to incoming queue %p, %d incoming\n", link->data, connection, connection->n_incoming); } @@ -3821,6 +3828,8 @@ dbus_connection_borrow_message (DBusConnection *connection) CONNECTION_UNLOCK (connection); + _dbus_message_trace_ref (message, -1, -1, "dbus_connection_borrow_message"); + /* We don't update dispatch status until it's returned or stolen */ return message; @@ -3855,6 +3864,8 @@ dbus_connection_return_message (DBusConnection *connection, status = _dbus_connection_get_dispatch_status_unlocked (connection); _dbus_connection_update_dispatch_status_and_unlock (connection, status); + + _dbus_message_trace_ref (message, -1, -1, "dbus_connection_return_message"); } /** @@ -3896,6 +3907,8 @@ dbus_connection_steal_borrowed_message (DBusConnection *connection, status = _dbus_connection_get_dispatch_status_unlocked (connection); _dbus_connection_update_dispatch_status_and_unlock (connection, status); + _dbus_message_trace_ref (message, -1, -1, + "dbus_connection_steal_borrowed_message"); } /* See dbus_connection_pop_message, but requires the caller to own @@ -3930,6 +3943,9 @@ _dbus_connection_pop_message_link_unlocked (DBusConnection *connection) dbus_message_get_signature (link->data), connection, connection->n_incoming); + _dbus_message_trace_ref (link->data, -1, -1, + "_dbus_connection_pop_message_link_unlocked"); + check_disconnected_message_arrived_unlocked (connection, link->data); return link; @@ -3991,6 +4007,9 @@ _dbus_connection_putback_message_link_unlocked (DBusConnection *connection, "no member", dbus_message_get_signature (message_link->data), connection, connection->n_incoming); + + _dbus_message_trace_ref (message_link->data, -1, -1, + "_dbus_connection_putback_message_link_unlocked"); } /** diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h index d4e8a6c..091d315 100644 --- a/dbus/dbus-message-internal.h +++ b/dbus/dbus-message-internal.h @@ -30,6 +30,21 @@ DBUS_BEGIN_DECLS +#ifdef DBUS_ENABLE_VERBOSE_MODE +void _dbus_message_trace_ref (DBusMessage *message, + int old_refcount, + int new_refcount, + const char *why); +#else +/* this bypasses any "unused" warnings for the old and new refcount */ +#define _dbus_message_trace_ref(m, o, n, w) \ + do \ + {\ + (void) (o); \ + (void) (n); \ + } while (0) +#endif + typedef struct DBusMessageLoader DBusMessageLoader; void _dbus_message_get_network_data (DBusMessage *message, diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 2ba5f5b..59a202c 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -83,6 +83,20 @@ _dbus_enable_message_cache (void) # define _dbus_enable_message_cache() (TRUE) #endif +#ifndef _dbus_message_trace_ref +void +_dbus_message_trace_ref (DBusMessage *message, + int old_refcount, + int new_refcount, + const char *why) +{ + static int enabled = -1; + + _dbus_trace_ref ("DBusMessage", message, old_refcount, new_refcount, why, + "DBUS_MESSAGE_TRACE", &enabled); +} +#endif + /* Not thread locked, but strictly const/read-only so should be OK */ /** An static string representing an empty signature */ @@ -1136,6 +1150,8 @@ dbus_message_new_empty_header (void) _dbus_atomic_inc (&message->refcount); + _dbus_message_trace_ref (message, 0, 1, "new_empty_header"); + message->locked = FALSE; #ifndef DBUS_DISABLE_CHECKS message->in_cache = FALSE; @@ -1542,6 +1558,7 @@ dbus_message_copy (const DBusMessage *message) #endif + _dbus_message_trace_ref (retval, 0, 1, "copy"); return retval; failed_copy: @@ -1569,20 +1586,15 @@ dbus_message_copy (const DBusMessage *message) DBusMessage * dbus_message_ref (DBusMessage *message) { -#ifndef DBUS_DISABLE_ASSERT dbus_int32_t old_refcount; -#endif _dbus_return_val_if_fail (message != NULL, NULL); _dbus_return_val_if_fail (message->generation == _dbus_current_generation, NULL); _dbus_return_val_if_fail (!message->in_cache, NULL); -#ifdef DBUS_DISABLE_ASSERT - _dbus_atomic_inc (&message->refcount); -#else old_refcount = _dbus_atomic_inc (&message->refcount); _dbus_assert (old_refcount >= 1); -#endif + _dbus_message_trace_ref (message, old_refcount, old_refcount + 1, "ref"); return message; } @@ -1607,6 +1619,8 @@ dbus_message_unref (DBusMessage *message) _dbus_assert (old_refcount >= 1); + _dbus_message_trace_ref (message, old_refcount, old_refcount - 1, "unref"); + if (old_refcount == 1) { /* Calls application callbacks! */ diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c index f961319..df2b2d6 100644 --- a/dbus/dbus-pending-call.c +++ b/dbus/dbus-pending-call.c @@ -24,6 +24,7 @@ #include #include "dbus-internals.h" #include "dbus-connection-internal.h" +#include "dbus-message-internal.h" #include "dbus-pending-call-internal.h" #include "dbus-pending-call.h" #include "dbus-list.h" @@ -680,7 +681,8 @@ dbus_pending_call_steal_reply (DBusPendingCall *pending) pending->reply = NULL; CONNECTION_UNLOCK (pending->connection); - + + _dbus_message_trace_ref (message, -1, -1, "dbus_pending_call_steal_reply"); return message; } -- 1.7.6.3