diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-07-26 16:28:41 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-13 17:54:54 +0000 |
commit | 0136f318f094f459adde3f0553110b1aba4bc199 (patch) | |
tree | 3b4130ea3d5bdcae46d8c4766579f26e41d2c078 /dbus/dbus-server.c | |
parent | 7ba7b9a931aa5a0959690f2512db7a7cd9f4b578 (diff) | |
download | dbus-0136f318f094f459adde3f0553110b1aba4bc199.tar.gz |
add and use _dbus_server_trace_ref
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37286
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Lennart Poettering <lennart@poettering.net>
Diffstat (limited to 'dbus/dbus-server.c')
-rw-r--r-- | dbus/dbus-server.c | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 5383a66a..157557cc 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -53,6 +53,20 @@ * @{ */ +#ifndef _dbus_server_trace_ref +void +_dbus_server_trace_ref (DBusServer *server, + int old_refcount, + int new_refcount, + const char *why) +{ + static int enabled = -1; + + _dbus_trace_ref ("DBusServer", server, old_refcount, new_refcount, why, + "DBUS_SERVER_TRACE", &enabled); +} +#endif + /* this is a little fragile since it assumes the address doesn't * already have a guid, but it shouldn't */ @@ -442,18 +456,15 @@ _dbus_server_toggle_timeout (DBusServer *server, void _dbus_server_ref_unlocked (DBusServer *server) { + dbus_int32_t old_refcount; + _dbus_assert (server != NULL); HAVE_LOCK_CHECK (server); -#ifdef DBUS_DISABLE_ASSERT - _dbus_atomic_inc (&server->refcount); -#else - { - dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount); - - _dbus_assert (old_refcount > 0); - } -#endif + old_refcount = _dbus_atomic_inc (&server->refcount); + _dbus_assert (old_refcount > 0); + _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, + "ref_unlocked"); } /** @@ -475,6 +486,9 @@ _dbus_server_unref_unlocked (DBusServer *server) old_refcount = _dbus_atomic_dec (&server->refcount); _dbus_assert (old_refcount > 0); + _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, + "unref_unlocked"); + if (old_refcount == 1) { _dbus_assert (server->disconnected); @@ -681,29 +695,27 @@ dbus_server_listen (const char *address, DBusServer * dbus_server_ref (DBusServer *server) { - _dbus_return_val_if_fail (server != NULL, NULL); + dbus_int32_t old_refcount; -#ifdef DBUS_DISABLE_CHECKS - _dbus_atomic_inc (&server->refcount); -#else - { - dbus_int32_t old_refcount; + _dbus_return_val_if_fail (server != NULL, NULL); - /* can't get the refcount without a side-effect */ - old_refcount = _dbus_atomic_inc (&server->refcount); + /* can't get the refcount without a side-effect */ + old_refcount = _dbus_atomic_inc (&server->refcount); - if (_DBUS_UNLIKELY (old_refcount <= 0)) - { - /* undo side-effect first */ - _dbus_atomic_dec (&server->refcount); - _dbus_warn_check_failed (_dbus_return_if_fail_warning_format, - _DBUS_FUNCTION_NAME, "old_refcount > 0", - __FILE__, __LINE__); - return NULL; - } +#ifndef DBUS_DISABLE_CHECKS + if (_DBUS_UNLIKELY (old_refcount <= 0)) + { + /* undo side-effect first */ + _dbus_atomic_dec (&server->refcount); + _dbus_warn_check_failed (_dbus_return_if_fail_warning_format, + _DBUS_FUNCTION_NAME, "old_refcount > 0", + __FILE__, __LINE__); + return NULL; } #endif + _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref"); + return server; } @@ -739,6 +751,8 @@ dbus_server_unref (DBusServer *server) } #endif + _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref"); + if (old_refcount == 1) { /* lock not held! */ |