/**
* All objects publicly exposed by Babeltrace APIs must contain this structure
* as their first member. This allows the unification of all ref counting
- * mechanism and may be used to provide more base functionality to all
+ * mechanisms and may be used to provide more base functionality to all
* objects.
*/
struct bt_object {
};
static inline
-long bt_object_get_ref_count(const void *);
-static inline
-void bt_object_set_parent(void *, void *);
+long bt_object_get_ref_count(const void *ptr)
+{
+ const struct bt_object *obj = ptr;
+
+ return obj->ref_count.count;
+}
-static
+static inline
void bt_object_release(void *ptr)
{
struct bt_object *obj = ptr;
}
}
-static
+static inline
void generic_release(struct bt_object *obj)
{
if (obj->parent) {
}
static inline
-struct bt_object *bt_object_get_parent(void *ptr)
+struct bt_object *bt_object_borrow_parent(void *ptr)
{
struct bt_object *obj = ptr;
- return ptr ? bt_get(obj->parent) : NULL;
+ return obj ? obj->parent : NULL;
+}
+
+static inline
+struct bt_object *bt_object_get_parent(void *ptr)
+{
+ return bt_get(bt_object_borrow_parent(ptr));
}
static inline
* to the parent will be released once the object's reference count
* falls to zero.
*/
+ BT_PUT(child->parent);
child->parent = bt_get(parent);
}
struct bt_object *obj = ptr;
obj->release = release;
+ obj->parent = NULL;
bt_ref_init(&obj->ref_count, generic_release);
}