From a04886ea66b5d691c3bb65457a20028c868b359c Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 20 Jan 2012 12:01:48 +0200 Subject: [PATCH] device: Add caller information to ref/unref debug prints. --- include/device.h | 14 ++++++++++++-- src/device.c | 12 +++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/device.h b/include/device.h index c1abe89..54beb65 100644 --- a/include/device.h +++ b/include/device.h @@ -55,8 +55,18 @@ struct connman_device; struct connman_device *connman_device_create(const char *node, enum connman_device_type type); -struct connman_device *connman_device_ref(struct connman_device *device); -void connman_device_unref(struct connman_device *device); + +#define connman_device_ref(device) \ + connman_device_ref_debug(device, __FILE__, __LINE__, __func__) + +#define connman_device_unref(device) \ + connman_device_unref_debug(device, __FILE__, __LINE__, __func__) + +struct connman_device * +connman_device_ref_debug(struct connman_device *device, + const char *file, int line, const char *caller); +void connman_device_unref_debug(struct connman_device *device, + const char *file, int line, const char *caller); enum connman_device_type connman_device_get_type(struct connman_device *device); void connman_device_set_index(struct connman_device *device, int index); diff --git a/src/device.c b/src/device.c index 2767347..30b7589 100644 --- a/src/device.c +++ b/src/device.c @@ -539,9 +539,11 @@ struct connman_device *connman_device_create(const char *node, * * Increase reference counter of device */ -struct connman_device *connman_device_ref(struct connman_device *device) +struct connman_device *connman_device_ref_debug(struct connman_device *device, + const char *file, int line, const char *caller) { - DBG("%p", device); + DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1, + file, line, caller); __sync_fetch_and_add(&device->refcount, 1); @@ -554,8 +556,12 @@ struct connman_device *connman_device_ref(struct connman_device *device) * * Decrease reference counter of device */ -void connman_device_unref(struct connman_device *device) +void connman_device_unref_debug(struct connman_device *device, + const char *file, int line, const char *caller) { + DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1, + file, line, caller); + if (__sync_fetch_and_sub(&device->refcount, 1) != 1) return; -- 2.7.4