X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=src%2Flib%2Fobject.h;h=2fbe7f02a2d275f0cdcaa9f373ff008e31dbd0b6;hb=50b9f4b57b59dd9524a6c463c64470b2aac9c429;hp=9d584c1bfd311bf2424fa5364fd1819a7ed1eea1;hpb=98b15851a941e7342b8bb19e265cdc3a40fabfb8;p=babeltrace.git diff --git a/src/lib/object.h b/src/lib/object.h index 9d584c1b..2fbe7f02 100644 --- a/src/lib/object.h +++ b/src/lib/object.h @@ -1,45 +1,17 @@ -#ifndef BABELTRACE_OBJECT_INTERNAL_H -#define BABELTRACE_OBJECT_INTERNAL_H - /* + * SPDX-License-Identifier: MIT + * * Copyright 2017-2018 Philippe Proulx * Copyright 2015 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. */ +#ifndef BABELTRACE_OBJECT_INTERNAL_H +#define BABELTRACE_OBJECT_INTERNAL_H + #include "common/macros.h" #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 *); @@ -138,7 +110,7 @@ void bt_object_set_parent(struct bt_object *child, struct bt_object *parent) 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 @@ -185,7 +157,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, @@ -275,7 +247,7 @@ void bt_object_get_ref_no_null_check_no_parent_check(const struct bt_object *c_o 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, @@ -294,7 +266,7 @@ void bt_object_get_ref_no_null_check(const void *c_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 +274,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, @@ -321,7 +293,7 @@ void bt_object_put_ref_no_null_check(const void *c_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, @@ -345,10 +317,7 @@ void bt_object_get_ref(const void *ptr) return; } -#ifdef BT_ASSERT_PRE_DEV - BT_ASSERT_PRE_DEV(obj->is_shared, "Object is not shared: %!+O", obj); -#endif - + BT_ASSERT_DBG(obj->is_shared); bt_object_get_ref_no_null_check(obj); } @@ -361,12 +330,8 @@ void bt_object_put_ref(const void *ptr) return; } -#ifdef BT_ASSERT_PRE_DEV - BT_ASSERT_PRE_DEV(obj->is_shared, "Object is not shared: %!+O", obj); - BT_ASSERT_PRE_DEV(bt_object_get_ref_count(obj) > 0, - "Decrementing a reference count set to 0: %!+O", ptr); -#endif - + BT_ASSERT_DBG(obj->is_shared); + BT_ASSERT_DBG(bt_object_get_ref_count(obj) > 0); bt_object_put_ref_no_null_check(obj); }