From 57f9090ab28b59f01b2f82d8193e4f7068fcf90f Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 20 Aug 2013 14:57:12 +0800 Subject: [PATCH 06/10] dbus-server.c: use the new _dbus_atomic_get function There were some codes written when there is no such _dbus_atomic_get() available, this patch fix these old codes with the new function. --- dbus/dbus-server.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 993b867..02cf5a3 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -456,8 +456,9 @@ _dbus_server_ref_unlocked (DBusServer *server) old_refcount = _dbus_atomic_inc (&server->refcount); _dbus_assert (old_refcount > 0); - _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, - "ref_unlocked"); + _dbus_server_trace_ref (server, old_refcount, + _dbus_atomic_get (&server->refcount), + "ref_unlocked"); } /** @@ -479,8 +480,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"); + _dbus_server_trace_ref (server, old_refcount, + _dbus_atomic_get (&server->refcount), + "unref_unlocked"); if (old_refcount == 1) { @@ -692,14 +694,11 @@ dbus_server_ref (DBusServer *server) _dbus_return_val_if_fail (server != NULL, NULL); - /* can't get the refcount without a side-effect */ - old_refcount = _dbus_atomic_inc (&server->refcount); + old_refcount = _dbus_atomic_get (&server->refcount); #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__); @@ -707,7 +706,10 @@ dbus_server_ref (DBusServer *server) } #endif - _dbus_server_trace_ref (server, old_refcount, old_refcount + 1, "ref"); + _dbus_atomic_inc (&server->refcount); + _dbus_server_trace_ref (server, old_refcount, + _dbus_atomic_get (&server->refcount), + "ref"); return server; } @@ -729,14 +731,11 @@ dbus_server_unref (DBusServer *server) _dbus_return_if_fail (server != NULL); - /* can't get the refcount without a side-effect */ - old_refcount = _dbus_atomic_dec (&server->refcount); + old_refcount = _dbus_atomic_get (&server->refcount); #ifndef DBUS_DISABLE_CHECKS if (_DBUS_UNLIKELY (old_refcount <= 0)) { - /* undo side-effect first */ - _dbus_atomic_inc (&server->refcount); _dbus_warn_check_failed (_dbus_return_if_fail_warning_format, _DBUS_FUNCTION_NAME, "old_refcount > 0", __FILE__, __LINE__); @@ -744,7 +743,10 @@ dbus_server_unref (DBusServer *server) } #endif - _dbus_server_trace_ref (server, old_refcount, old_refcount - 1, "unref"); + _dbus_atomic_dec (&server->refcount); + _dbus_server_trace_ref (server, old_refcount, + _dbus_atomic_get (&server->refcount), + "unref"); if (old_refcount == 1) { @@ -769,16 +771,9 @@ void dbus_server_disconnect (DBusServer *server) { _dbus_return_if_fail (server != NULL); + _dbus_return_if_fail (_dbus_atomic_get (&server->refcount) > 0); -#ifdef DBUS_DISABLE_CHECKS _dbus_atomic_inc (&server->refcount); -#else - { - dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount); - - _dbus_return_if_fail (old_refcount > 0); - } -#endif SERVER_LOCK (server); -- 1.7.9.5