mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-02-18 18:50:29 +01:00
Merge branch 'dbus-1.4'
This commit is contained in:
commit
e9197996fe
2 changed files with 74 additions and 76 deletions
|
|
@ -133,8 +133,8 @@ _dbus_pending_call_new_unlocked (DBusConnection *connection,
|
|||
{
|
||||
pending->timeout = NULL;
|
||||
}
|
||||
|
||||
pending->refcount.value = 1;
|
||||
|
||||
_dbus_atomic_inc (&pending->refcount);
|
||||
pending->connection = connection;
|
||||
_dbus_connection_ref_unlocked (pending->connection);
|
||||
|
||||
|
|
@ -374,8 +374,8 @@ _dbus_pending_call_set_timeout_error_unlocked (DBusPendingCall *pending,
|
|||
DBusPendingCall *
|
||||
_dbus_pending_call_ref_unlocked (DBusPendingCall *pending)
|
||||
{
|
||||
pending->refcount.value += 1;
|
||||
|
||||
_dbus_atomic_inc (&pending->refcount);
|
||||
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
|
@ -433,15 +433,14 @@ _dbus_pending_call_last_unref (DBusPendingCall *pending)
|
|||
void
|
||||
_dbus_pending_call_unref_and_unlock (DBusPendingCall *pending)
|
||||
{
|
||||
dbus_bool_t last_unref;
|
||||
|
||||
_dbus_assert (pending->refcount.value > 0);
|
||||
dbus_int32_t old_refcount;
|
||||
|
||||
pending->refcount.value -= 1;
|
||||
last_unref = pending->refcount.value == 0;
|
||||
old_refcount = _dbus_atomic_dec (&pending->refcount);
|
||||
_dbus_assert (old_refcount > 0);
|
||||
|
||||
CONNECTION_UNLOCK (pending->connection);
|
||||
if (last_unref)
|
||||
|
||||
if (old_refcount == 1)
|
||||
_dbus_pending_call_last_unref (pending);
|
||||
}
|
||||
|
||||
|
|
@ -554,19 +553,8 @@ dbus_pending_call_ref (DBusPendingCall *pending)
|
|||
{
|
||||
_dbus_return_val_if_fail (pending != NULL, NULL);
|
||||
|
||||
/* The connection lock is better than the global
|
||||
* lock in the atomic increment fallback
|
||||
*/
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
_dbus_atomic_inc (&pending->refcount);
|
||||
#else
|
||||
CONNECTION_LOCK (pending->connection);
|
||||
_dbus_assert (pending->refcount.value > 0);
|
||||
|
||||
pending->refcount.value += 1;
|
||||
CONNECTION_UNLOCK (pending->connection);
|
||||
#endif
|
||||
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
|
@ -583,19 +571,8 @@ dbus_pending_call_unref (DBusPendingCall *pending)
|
|||
|
||||
_dbus_return_if_fail (pending != NULL);
|
||||
|
||||
/* More efficient to use the connection lock instead of atomic
|
||||
* int fallback if we lack atomic int decrement
|
||||
*/
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
last_unref = (_dbus_atomic_dec (&pending->refcount) == 1);
|
||||
#else
|
||||
CONNECTION_LOCK (pending->connection);
|
||||
_dbus_assert (pending->refcount.value > 0);
|
||||
pending->refcount.value -= 1;
|
||||
last_unref = pending->refcount.value == 0;
|
||||
CONNECTION_UNLOCK (pending->connection);
|
||||
#endif
|
||||
|
||||
|
||||
if (last_unref)
|
||||
_dbus_pending_call_last_unref(pending);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,16 @@ _dbus_server_init_base (DBusServer *server,
|
|||
const DBusString *address)
|
||||
{
|
||||
server->vtable = vtable;
|
||||
server->refcount.value = 1;
|
||||
|
||||
#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
|
||||
|
||||
server->address = NULL;
|
||||
server->watches = NULL;
|
||||
|
|
@ -434,16 +443,16 @@ void
|
|||
_dbus_server_ref_unlocked (DBusServer *server)
|
||||
{
|
||||
_dbus_assert (server != NULL);
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
|
||||
HAVE_LOCK_CHECK (server);
|
||||
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
#ifdef DBUS_DISABLE_ASSERT
|
||||
_dbus_atomic_inc (&server->refcount);
|
||||
#else
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
{
|
||||
dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
|
||||
|
||||
server->refcount.value += 1;
|
||||
_dbus_assert (old_refcount > 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -455,25 +464,18 @@ _dbus_server_ref_unlocked (DBusServer *server)
|
|||
void
|
||||
_dbus_server_unref_unlocked (DBusServer *server)
|
||||
{
|
||||
dbus_bool_t last_unref;
|
||||
dbus_int32_t old_refcount;
|
||||
|
||||
/* Keep this in sync with dbus_server_unref */
|
||||
|
||||
|
||||
_dbus_assert (server != NULL);
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
|
||||
HAVE_LOCK_CHECK (server);
|
||||
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
last_unref = (_dbus_atomic_dec (&server->refcount) == 1);
|
||||
#else
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
|
||||
server->refcount.value -= 1;
|
||||
last_unref = (server->refcount.value == 0);
|
||||
#endif
|
||||
|
||||
if (last_unref)
|
||||
old_refcount = _dbus_atomic_dec (&server->refcount);
|
||||
_dbus_assert (old_refcount > 0);
|
||||
|
||||
if (old_refcount == 1)
|
||||
{
|
||||
_dbus_assert (server->disconnected);
|
||||
|
||||
|
|
@ -680,16 +682,26 @@ DBusServer *
|
|||
dbus_server_ref (DBusServer *server)
|
||||
{
|
||||
_dbus_return_val_if_fail (server != NULL, NULL);
|
||||
_dbus_return_val_if_fail (server->refcount.value > 0, NULL);
|
||||
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
#ifdef DBUS_DISABLE_CHECKS
|
||||
_dbus_atomic_inc (&server->refcount);
|
||||
#else
|
||||
SERVER_LOCK (server);
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
{
|
||||
dbus_int32_t old_refcount;
|
||||
|
||||
server->refcount.value += 1;
|
||||
SERVER_UNLOCK (server);
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return server;
|
||||
|
|
@ -706,27 +718,28 @@ dbus_server_ref (DBusServer *server)
|
|||
void
|
||||
dbus_server_unref (DBusServer *server)
|
||||
{
|
||||
dbus_bool_t last_unref;
|
||||
dbus_int32_t old_refcount;
|
||||
|
||||
/* keep this in sync with unref_unlocked */
|
||||
|
||||
|
||||
_dbus_return_if_fail (server != NULL);
|
||||
_dbus_return_if_fail (server->refcount.value > 0);
|
||||
|
||||
#ifdef DBUS_HAVE_ATOMIC_INT
|
||||
last_unref = (_dbus_atomic_dec (&server->refcount) == 1);
|
||||
#else
|
||||
SERVER_LOCK (server);
|
||||
|
||||
_dbus_assert (server->refcount.value > 0);
|
||||
/* can't get the refcount without a side-effect */
|
||||
old_refcount = _dbus_atomic_dec (&server->refcount);
|
||||
|
||||
server->refcount.value -= 1;
|
||||
last_unref = (server->refcount.value == 0);
|
||||
|
||||
SERVER_UNLOCK (server);
|
||||
#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__);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (last_unref)
|
||||
|
||||
if (old_refcount == 1)
|
||||
{
|
||||
/* lock not held! */
|
||||
_dbus_assert (server->disconnected);
|
||||
|
|
@ -749,11 +762,19 @@ void
|
|||
dbus_server_disconnect (DBusServer *server)
|
||||
{
|
||||
_dbus_return_if_fail (server != NULL);
|
||||
_dbus_return_if_fail (server->refcount.value > 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);
|
||||
_dbus_server_ref_unlocked (server);
|
||||
|
||||
|
||||
_dbus_assert (server->vtable->disconnect != NULL);
|
||||
|
||||
if (!server->disconnected)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue