X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fobject-internal.h;h=e130a81e883d620cba525cffc28a4ffba2f90fcd;hb=dc3fffef7b84cc4af1a7c99828fd57a106cd2257;hp=fb37d97a3bf485e4d0d2e291dffad5b768bdd5c6;hpb=78586d8a10bfb11d34d187697ae15e9255c6ddf4;p=babeltrace.git diff --git a/include/babeltrace/object-internal.h b/include/babeltrace/object-internal.h index fb37d97a..e130a81e 100644 --- a/include/babeltrace/object-internal.h +++ b/include/babeltrace/object-internal.h @@ -45,11 +45,14 @@ 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; @@ -59,7 +62,7 @@ void bt_object_release(void *ptr) } } -static +static inline void generic_release(struct bt_object *obj) { if (obj->parent) { @@ -71,11 +74,17 @@ void generic_release(struct bt_object *obj) } 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 @@ -93,6 +102,7 @@ void bt_object_set_parent(void *child_ptr, void *parent) * to the parent will be released once the object's reference count * falls to zero. */ + BT_PUT(child->parent); child->parent = bt_get(parent); } @@ -106,12 +116,4 @@ void bt_object_init(void *ptr, bt_object_release_func release) bt_ref_init(&obj->ref_count, generic_release); } -static inline -long bt_object_get_ref_count(const void *ptr) -{ - const struct bt_object *obj = ptr; - - return obj->ref_count.count; -} - #endif /* BABELTRACE_OBJECT_INTERNAL_H */