+ bt_object_try_spec_release(obj);
+ }
+}
+
+static inline
+void bt_object_init(struct bt_object *obj, bool is_shared,
+ bt_object_release_func release_func)
+{
+ BT_ASSERT(obj);
+ BT_ASSERT(!is_shared || release_func);
+ obj->is_shared = is_shared;
+ obj->release_func = release_func;
+ obj->parent_is_owner_listener_func = NULL;
+ obj->spec_release_func = NULL;
+ obj->parent = NULL;
+ obj->ref_count = 1;
+}
+
+static inline
+void bt_object_init_shared(struct bt_object *obj,
+ bt_object_release_func release_func)
+{
+ bt_object_init(obj, true, release_func);
+}
+
+static inline
+void bt_object_init_unique(struct bt_object *obj)
+{
+ bt_object_init(obj, false, NULL);
+}
+
+static inline
+void bt_object_init_shared_with_parent(struct bt_object *obj,
+ bt_object_release_func spec_release_func)
+{
+ BT_ASSERT(obj);
+ BT_ASSERT(spec_release_func);
+ bt_object_init_shared(obj, bt_object_with_parent_release_func);
+ obj->spec_release_func = spec_release_func;
+}
+
+static inline
+void bt_object_set_parent_is_owner_listener_func(struct bt_object *obj,
+ bt_object_parent_is_owner_listener_func func)
+{
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ BT_ASSERT(obj->spec_release_func);
+ ((struct bt_object *) obj)->parent_is_owner_listener_func = func;
+}
+
+static inline
+void bt_object_inc_ref_count(const struct bt_object *c_obj)
+{
+ struct bt_object *obj = (void *) c_obj;
+
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ obj->ref_count++;
+ BT_ASSERT(obj->ref_count != 0);
+}
+
+static inline
+void bt_object_get_no_null_check_no_parent_check(const struct bt_object *c_obj)
+{
+ struct bt_object *obj = (void *) c_obj;
+
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+
+#ifdef BT_LOGV
+ BT_LOGV("Incrementing object's reference count: %llu -> %llu: "
+ "addr=%p, cur-count=%llu, new-count=%llu",
+ obj->ref_count, obj->ref_count + 1,
+ obj, obj->ref_count, obj->ref_count + 1);
+#endif
+
+ bt_object_inc_ref_count(obj);
+}
+
+static inline
+void bt_object_get_no_null_check(const void *c_obj)
+{
+ struct bt_object *obj = (void *) c_obj;
+
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+
+ if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) {
+#ifdef BT_LOGV
+ BT_LOGV("Incrementing object's parent's reference count: "
+ "addr=%p, parent-addr=%p", obj, obj->parent);
+#endif
+
+ bt_object_get_no_null_check(obj->parent);