X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fref.c;h=02d2c4e9bf914fe3467600d81ea4d5abd13058d9;hb=149bc52e92f860f992d02ca19371ca8d8321f3df;hp=ac0580137a5ad959d25fbfa29b3a3dc0a7ffae19;hpb=b703b34e4cc4af21278e5eec8f01e5c40687a10b;p=babeltrace.git diff --git a/lib/ref.c b/lib/ref.c index ac058013..02d2c4e9 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -24,6 +24,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "REF" +#include + #include #include @@ -31,14 +34,26 @@ void *bt_get(void *ptr) { struct bt_object *obj = ptr; - if (!obj) { + if (unlikely(!obj)) { goto end; } - if (obj->parent && bt_object_get_ref_count(obj) == 0) { + if (unlikely(!obj->ref_count.release)) { + goto end; + } + + if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) { + BT_LOGV("Incrementing object's parent's reference count: " + "addr=%p, parent-addr=%p", ptr, obj->parent); bt_get(obj->parent); } + BT_LOGV("Incrementing object's reference count: %lu -> %lu: " + "addr=%p, cur-count=%lu, new-count=%lu", + obj->ref_count.count, obj->ref_count.count + 1, + ptr, + obj->ref_count.count, obj->ref_count.count + 1); bt_ref_get(&obj->ref_count); + end: return obj; } @@ -47,9 +62,23 @@ void bt_put(void *ptr) { struct bt_object *obj = ptr; - if (!obj) { + if (unlikely(!obj)) { return; } + if (unlikely(!obj->ref_count.release)) { + return; + } + + if (BT_LOG_ON_WARN && unlikely(bt_object_get_ref_count(obj) == 0)) { + BT_LOGW("Decrementing a reference count set to 0: addr=%p", + ptr); + } + + BT_LOGV("Decrementing object's reference count: %lu -> %lu: " + "addr=%p, cur-count=%lu, new-count=%lu", + obj->ref_count.count, obj->ref_count.count - 1, + ptr, + obj->ref_count.count, obj->ref_count.count - 1); bt_ref_put(&obj->ref_count); }