diff --git a/dbus/dbus-resources.c b/dbus/dbus-resources.c index 80fb55b..991bb58 100644 --- a/dbus/dbus-resources.c +++ b/dbus/dbus-resources.c @@ -53,7 +53,7 @@ */ struct DBusCounter { - int refcount; /**< reference count */ + DBusAtomic refcount; /**< reference count */ long size_value; /**< current size counter value */ long unix_fd_value; /**< current unix fd counter value */ @@ -93,7 +93,7 @@ _dbus_counter_new (void) if (counter == NULL) return NULL; - counter->refcount = 1; + _dbus_atomic_inc (&counter->refcount); return counter; } @@ -107,9 +107,9 @@ _dbus_counter_new (void) DBusCounter * _dbus_counter_ref (DBusCounter *counter) { - _dbus_assert (counter->refcount > 0); + _dbus_assert (_dbus_atomic_get (&counter->refcount) > 0); - counter->refcount += 1; + _dbus_atomic_inc (&counter->refcount); return counter; } @@ -123,11 +123,13 @@ _dbus_counter_ref (DBusCounter *counter) void _dbus_counter_unref (DBusCounter *counter) { - _dbus_assert (counter->refcount > 0); + dbus_int32_t old_refcount; - counter->refcount -= 1; + old_refcount = _dbus_atomic_dec (&counter->refcount); - if (counter->refcount == 0) + _dbus_assert (old_refcount >= 1); + + if (old_refcount == 1) { dbus_free (counter);