* SOFTWARE.
*/
-#include <babeltrace/ref-internal.h>
+#define BT_LOG_TAG "REF"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/object-internal.h>
-void bt_get(void *obj)
+void *bt_get(void *ptr)
{
- if (obj) {
- struct bt_object *base = obj;
+ struct bt_object *obj = ptr;
- bt_ref_get(&base->ref_count);
+ if (unlikely(!obj)) {
+ goto end;
}
+
+ BT_ASSERT_PRE(obj->is_shared, "Object is not shared: addr=%p", obj);
+ bt_object_get_no_null_check(obj);
+
+end:
+ return ptr;
}
-void bt_put(void *obj)
+void bt_put(void *ptr)
{
- if (obj) {
- struct bt_object *base = obj;
+ struct bt_object *obj = ptr;
- bt_ref_put(&base->ref_count);
+ if (unlikely(!obj)) {
+ return;
}
+
+ BT_ASSERT_PRE(obj->is_shared, "Object is not shared: addr=%p", obj);
+ BT_ASSERT_PRE(bt_object_get_ref_count(obj) > 0,
+ "Decrementing a reference count set to 0: addr=%p", ptr);
+ bt_object_put_no_null_check(obj);
}