X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fobject.h;h=c7cbb123f82b673a17ee89c91bed7dbc7e1b65b9;hb=36e94ad605ae7ee5d31a3acb1d20d65de95f9e11;hp=25240b2000b2510074eaee8fcae143d4abb234ac;hpb=6871026b82224d83bb63cbb44cc33c16c766d96d;p=babeltrace.git diff --git a/src/lib/object.h b/src/lib/object.h index 25240b20..c7cbb123 100644 --- a/src/lib/object.h +++ b/src/lib/object.h @@ -28,18 +28,6 @@ #include "common/assert.h" #include -/* - * Some parts of the Babeltrace project use this internal library header - * for internal reference counting. Until we make this header generic - * for the whole project, make it possible to disable logging in this - * file by defining `BT_OBJECT_DONT_LOG` because it's possible that the - * BT_LOGT() statements here won't find the log level - * (`BT_LOG_OUTPUT_LEVEL`). - */ -#if defined(BT_LOGT) && !defined(BT_OBJECT_DONT_LOG) -# define _BT_OBJECT_LOGGING_ENABLED -#endif - struct bt_object; typedef void (*bt_object_release_func)(struct bt_object *); @@ -104,8 +92,8 @@ unsigned long long bt_object_get_ref_count(const struct bt_object *c_obj) { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); return obj->ref_count; } @@ -114,8 +102,8 @@ struct bt_object *bt_object_borrow_parent(const struct bt_object *c_obj) { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); return obj->parent; } @@ -135,10 +123,10 @@ struct bt_object *bt_object_get_parent(const struct bt_object *c_obj) static inline void bt_object_set_parent(struct bt_object *child, struct bt_object *parent) { - BT_ASSERT(child); - BT_ASSERT(child->is_shared); + BT_ASSERT_DBG(child); + BT_ASSERT_DBG(child->is_shared); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Setting object's parent: addr=%p, parent-addr=%p", child, parent); #endif @@ -150,7 +138,7 @@ void bt_object_set_parent(struct bt_object *child, struct bt_object *parent) * object's reference count falls to zero. */ if (parent) { - BT_ASSERT(!child->parent); + BT_ASSERT_DBG(!child->parent); child->parent = parent; bt_object_get_ref_no_null_check(parent); } else { @@ -165,9 +153,9 @@ void bt_object_set_parent(struct bt_object *child, struct bt_object *parent) static inline void bt_object_try_spec_release(struct bt_object *obj) { - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); - BT_ASSERT(obj->spec_release_func); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); + BT_ASSERT_DBG(obj->spec_release_func); if (bt_object_get_ref_count(obj) == 0) { obj->spec_release_func(obj); @@ -185,7 +173,7 @@ void bt_object_with_parent_release_func(struct bt_object *obj) */ struct bt_object *parent = obj->parent; -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Releasing parented object: addr=%p, ref-count=%llu, " "parent-addr=%p, parent-ref-count=%llu", obj, obj->ref_count, @@ -213,8 +201,8 @@ static inline void bt_object_init(struct bt_object *obj, bool is_shared, bt_object_release_func release_func) { - BT_ASSERT(obj); - BT_ASSERT(!is_shared || release_func); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(!is_shared || release_func); obj->is_shared = is_shared; obj->release_func = release_func; obj->parent_is_owner_listener_func = NULL; @@ -240,8 +228,8 @@ static inline void bt_object_init_shared_with_parent(struct bt_object *obj, bt_object_release_func spec_release_func) { - BT_ASSERT(obj); - BT_ASSERT(spec_release_func); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(spec_release_func); bt_object_init_shared(obj, bt_object_with_parent_release_func); obj->spec_release_func = spec_release_func; } @@ -250,9 +238,9 @@ static inline void bt_object_set_parent_is_owner_listener_func(struct bt_object *obj, bt_object_parent_is_owner_listener_func func) { - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); - BT_ASSERT(obj->spec_release_func); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); + BT_ASSERT_DBG(obj->spec_release_func); ((struct bt_object *) obj)->parent_is_owner_listener_func = func; } @@ -261,10 +249,10 @@ void bt_object_inc_ref_count(const struct bt_object *c_obj) { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); obj->ref_count++; - BT_ASSERT(obj->ref_count != 0); + BT_ASSERT_DBG(obj->ref_count != 0); } static inline @@ -272,10 +260,10 @@ void bt_object_get_ref_no_null_check_no_parent_check(const struct bt_object *c_o { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count + 1, @@ -290,11 +278,11 @@ void bt_object_get_ref_no_null_check(const void *c_obj) { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); if (G_UNLIKELY(obj->parent && bt_object_get_ref_count(obj) == 0)) { -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's parent's reference count: " "addr=%p, parent-addr=%p", obj, obj->parent); #endif @@ -302,7 +290,7 @@ void bt_object_get_ref_no_null_check(const void *c_obj) bt_object_get_ref_no_null_check(obj->parent); } -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Incrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count + 1, @@ -317,11 +305,11 @@ void bt_object_put_ref_no_null_check(const void *c_obj) { struct bt_object *obj = (void *) c_obj; - BT_ASSERT(obj); - BT_ASSERT(obj->is_shared); - BT_ASSERT(obj->ref_count > 0); + BT_ASSERT_DBG(obj); + BT_ASSERT_DBG(obj->is_shared); + BT_ASSERT_DBG(obj->ref_count > 0); -#ifdef _BT_OBJECT_LOGGING_ENABLED +#ifdef BT_LOGT BT_LOGT("Decrementing object's reference count: %llu -> %llu: " "addr=%p, cur-count=%llu, new-count=%llu", obj->ref_count, obj->ref_count - 1, @@ -331,7 +319,7 @@ void bt_object_put_ref_no_null_check(const void *c_obj) obj->ref_count--; if (obj->ref_count == 0) { - BT_ASSERT(obj->release_func); + BT_ASSERT_DBG(obj->release_func); obj->release_func(obj); } }