From f1e7f81efecda34338e3b4245ac419db5a236192 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 20 Jan 2013 16:13:05 -0800 Subject: [PATCH] core: Use same reference counting as adapter handling --- src/device.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/device.c b/src/device.c index e1219c4bb..a760f786e 100644 --- a/src/device.c +++ b/src/device.c @@ -139,6 +139,8 @@ struct att_callbacks { }; struct btd_device { + int ref_count; + bdaddr_t bdaddr; uint8_t bdaddr_type; char *path; @@ -188,8 +190,6 @@ struct btd_device { bool legacy; int8_t rssi; - gint ref; - GIOChannel *att_io; guint cleanup_id; guint store_id; @@ -3981,21 +3981,22 @@ const sdp_record_t *btd_device_get_record(struct btd_device *device, struct btd_device *btd_device_ref(struct btd_device *device) { - device->ref++; - - DBG("%p: ref=%d", device, device->ref); + __sync_fetch_and_add(&device->ref_count, 1); return device; } void btd_device_unref(struct btd_device *device) { - device->ref--; - - DBG("%p: ref=%d", device, device->ref); + if (__sync_sub_and_fetch(&device->ref_count, 1)) + return; - if (device->ref > 0) + if (!device->path) { + error("freeing device without an object path"); return; + } + + DBG("Freeing device %s", device->path); g_dbus_unregister_interface(dbus_conn, device->path, DEVICE_INTERFACE); } -- 2.47.3