Fix: set BT object's shared flag in all modes
[babeltrace.git] / include / babeltrace / object-internal.h
index 2b368c5510e46f86ea26758b44e8c939a0346ae6..afb9e6eee3cb0cebe2137273bb1fbc637cd43d71 100644 (file)
  * SOFTWARE.
  */
 
+#include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ref-internal.h>
 #include <babeltrace/ref.h>
+#include <babeltrace/assert-internal.h>
+#include <stdbool.h>
 
 /**
  * All objects publicly exposed by Babeltrace APIs must contain this structure
@@ -44,6 +47,12 @@ struct bt_object {
        bt_object_release_func parent_is_owner_listener;
        /* @see doc/ref-counting.md */
        struct bt_object *parent;
+
+       /*
+        * True if this object is shared, that is, it uses reference
+        * counting.
+        */
+       bool is_shared;
 };
 
 static inline
@@ -64,7 +73,7 @@ void bt_object_release(void *ptr)
                obj->ref_count.count);
 #endif
 
-       if (obj && obj->release && !bt_object_get_ref_count(obj)) {
+       if (obj && obj->release && bt_object_get_ref_count(obj) == 0) {
                obj->release(obj);
        }
 }
@@ -128,15 +137,21 @@ void bt_object_set_parent(void *child_ptr, void *parent)
 #endif
 
        /*
-        * It is assumed that a "child" being "parented" is publicly reachable.
-        * Therefore, a reference to its parent must be taken. The reference
-        * to the parent will be released once the object's reference count
-        * falls to zero.
+        * It is assumed that a "child" being "parented" is publicly
+        * reachable. Therefore, a reference to its parent must be
+        * taken. The reference to the parent will be released once the
+        * object's reference count falls to zero.
         */
        BT_PUT(child->parent);
        child->parent = bt_get(parent);
 }
 
+static inline
+void bt_object_set_is_shared(struct bt_object *obj, bool is_shared)
+{
+       obj->is_shared = is_shared;
+}
+
 static inline
 void bt_object_init(void *ptr, bt_object_release_func release)
 {
@@ -144,6 +159,7 @@ void bt_object_init(void *ptr, bt_object_release_func release)
 
        obj->release = release;
        obj->parent = NULL;
+       bt_object_set_is_shared(obj, true);
        bt_ref_init(&obj->ref_count, generic_release);
 }
 
@@ -151,7 +167,7 @@ static inline
 void bt_object_set_parent_is_owner_listener(void *obj,
                bt_object_release_func cb)
 {
-       assert(obj);
+       BT_ASSERT(obj);
        ((struct bt_object *) obj)->parent_is_owner_listener = cb;
 }
 
This page took 0.02383 seconds and 4 git commands to generate.