Values API: standardize function names
[babeltrace.git] / lib / ref.c
index 97460e93522a84505637d3ba80d69fb85c416405..ae2cef017745e5aacac0e50e67b997478ae32720 100644 (file)
--- a/lib/ref.c
+++ b/lib/ref.c
  * 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 *ptr)
 {
        struct bt_object *obj = ptr;
 
-       if (!obj) {
+       if (unlikely(!obj)) {
                goto end;
        }
 
-       if (obj->parent && bt_object_get_ref_count(obj) == 0) {
-               bt_get(obj->parent);
-       }
-       bt_ref_get(&obj->ref_count);
+       BT_ASSERT_PRE(obj->is_shared, "Object is not shared: addr=%p", obj);
+       bt_object_get_no_null_check(obj);
+
 end:
-       return obj;
+       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);
 }
This page took 0.023573 seconds and 4 git commands to generate.