goto error;
}
- bt_object_init(cfg_component, bt_config_component_destroy);
+ bt_object_init_shared(&cfg_component->base,
+ bt_config_component_destroy);
cfg_component->type = type;
cfg_component->plugin_name = g_string_new(plugin_name);
if (!cfg_component->plugin_name) {
goto error;
}
- bt_object_init(cfg, bt_config_destroy);
+ bt_object_init_shared(&cfg->base, bt_config_destroy);
cfg->command = command;
cfg->command_needs_plugins = needs_plugins;
babeltrace/compiler-internal.h \
babeltrace/babeltrace-internal.h \
babeltrace/assert-pre-internal.h \
- babeltrace/ref-internal.h \
babeltrace/graph/component-internal.h \
babeltrace/graph/notification-stream-internal.h \
babeltrace/graph/connection-internal.h \
struct bt_event_class_common *event_class)
{
BT_ASSERT(event_class);
- return (void *) bt_object_borrow_parent(event_class);
+ return (void *) bt_object_borrow_parent(&event_class->base);
}
typedef struct bt_field_type_common *(*bt_field_type_structure_create_func)();
int bt_event_common_initialize(struct bt_event_common *event,
struct bt_event_class_common *event_class,
struct bt_clock_class *init_expected_clock_class,
- bt_object_release_func release_func,
+ bool is_shared_with_parent, bt_object_release_func release_func,
bt_validation_flag_copy_field_type_func field_type_copy_func,
bool must_be_in_trace,
int (*map_clock_classes_func)(struct bt_stream_class_common *stream_class,
BT_HIDDEN
int bt_field_common_structure_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_release_func);
BT_HIDDEN
int bt_field_common_array_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_destroy_func);
BT_HIDDEN
int bt_field_common_sequence_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
GDestroyNotify field_destroy_func);
BT_HIDDEN
int bt_field_common_variant_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_release_func);
BT_HIDDEN
int bt_field_common_string_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods);
BT_HIDDEN
static inline
void bt_field_common_initialize(struct bt_field_common *field,
- struct bt_field_type_common *ft,
+ struct bt_field_type_common *ft, bool is_shared,
bt_object_release_func release_func,
struct bt_field_common_methods *methods)
{
BT_ASSERT(field);
BT_ASSERT(ft);
- bt_object_init(field, release_func);
+ bt_object_init(&field->base, is_shared, release_func);
field->methods = methods;
field->type = bt_get(ft);
}
struct bt_stream_class_common *stream_class)
{
BT_ASSERT(stream_class);
- return (void *) bt_object_borrow_parent(stream_class);
+ return (void *) bt_object_borrow_parent(&stream_class->base);
}
static inline
* SOFTWARE.
*/
-#include <babeltrace/ref-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/graph/graph.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/object-internal.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/graph/connection.h>
#include <babeltrace/graph/notification.h>
#include <babeltrace/graph/notification-iterator.h>
*/
#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
- * as their first member. This allows the unification of all ref counting
- * mechanisms and may be used to provide more base functionality to all
- * objects.
+struct bt_object;
+
+typedef void (*bt_object_release_func)(struct bt_object *);
+typedef void (*bt_object_parent_is_owner_listener_func)(
+ struct bt_object *);
+
+static inline
+void bt_object_get_no_null_check(struct bt_object *obj);
+
+static inline
+void bt_object_put_no_null_check(struct bt_object *obj);
+
+/*
+ * Babeltrace object base.
+ *
+ * All objects publicly exposed by Babeltrace APIs must contain this
+ * object as their first member.
*/
struct bt_object {
- struct bt_ref ref_count;
- /* Class-specific, optional release function. */
- bt_object_release_func release;
- /* Class-specific, optional "parent is owner" notification listener. */
- 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.
+ * True if this object is shared, that is, it has a reference
+ * count.
*/
bool is_shared;
+
+ /*
+ * Current reference count.
+ */
+ unsigned long long ref_count;
+
+ /*
+ * Release function called when the object's reference count
+ * falls to zero. For an object with a parent, this function is
+ * bt_object_with_parent_release_func(), which calls
+ * `spec_release_func` below if there's no current parent.
+ */
+ bt_object_release_func release_func;
+
+ /*
+ * Specific release function called by
+ * bt_object_with_parent_release_func() or directly by a
+ * parent object.
+ */
+ bt_object_release_func spec_release_func;
+
+ /*
+ * Optional callback for an object with a parent, called by
+ * bt_object_with_parent_release_func() to indicate to the
+ * object that its parent is its owner.
+ */
+ bt_object_parent_is_owner_listener_func
+ parent_is_owner_listener_func;
+
+ /*
+ * Optional parent object.
+ */
+ struct bt_object *parent;
};
static inline
-long bt_object_get_ref_count(const void *ptr)
+unsigned long long bt_object_get_ref_count(struct bt_object *obj)
{
- const struct bt_object *obj = ptr;
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ return obj->ref_count;
+}
- return obj->ref_count.count;
+static inline
+struct bt_object *bt_object_borrow_parent(struct bt_object *obj)
+{
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ return obj->parent;
}
static inline
-void bt_object_release(void *ptr)
+struct bt_object *bt_object_get_parent(struct bt_object *obj)
{
- struct bt_object *obj = ptr;
+ struct bt_object *parent = bt_object_borrow_parent(obj);
+
+ if (parent) {
+ bt_object_get_no_null_check(parent);
+ }
+
+ return parent;
+}
+
+static inline
+void bt_object_set_parent(struct bt_object *child, struct bt_object *parent)
+{
+ BT_ASSERT(child);
+ BT_ASSERT(child->is_shared);
#ifdef BT_LOGV
- BT_LOGV("Releasing object: addr=%p, ref-count=%lu", ptr,
- obj->ref_count.count);
+ BT_LOGV("Setting object's parent: addr=%p, parent-addr=%p",
+ child, parent);
#endif
- if (obj && obj->release && bt_object_get_ref_count(obj) == 0) {
- obj->release(obj);
+ /*
+ * It is assumed that a "child" having a parent 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.
+ */
+ if (parent) {
+ BT_ASSERT(!child->parent);
+ child->parent = parent;
+ bt_object_get_no_null_check(parent);
+ } else {
+ if (child->parent) {
+ bt_object_put_no_null_check(child->parent);
+ }
+
+ child->parent = NULL;
}
}
static inline
-void generic_release(struct bt_object *obj)
+void bt_object_try_spec_release(struct bt_object *obj)
+{
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ BT_ASSERT(obj->spec_release_func);
+
+ if (bt_object_get_ref_count(obj) == 0) {
+ obj->spec_release_func(obj);
+ }
+}
+
+static inline
+void bt_object_with_parent_release_func(struct bt_object *obj)
{
if (obj->parent) {
+ /*
+ * Keep our own copy of the parent address because `obj`
+ * could be destroyed in
+ * obj->parent_is_owner_listener_func().
+ */
struct bt_object *parent = obj->parent;
#ifdef BT_LOGV
- BT_LOGV("Releasing parented object: addr=%p, ref-count=%lu, "
- "parent-addr=%p, parent-ref-count=%lu",
- obj, obj->ref_count.count,
- parent, parent->ref_count.count);
+ BT_LOGV("Releasing parented object: addr=%p, ref-count=%llu, "
+ "parent-addr=%p, parent-ref-count=%llu",
+ obj, obj->ref_count,
+ parent, parent->ref_count);
#endif
- if (obj->parent_is_owner_listener) {
+ if (obj->parent_is_owner_listener_func) {
/*
* Object has a chance to destroy itself here
* under certain conditions and notify its
* parent. At this point the parent is
* guaranteed to exist because it's not put yet.
*/
- obj->parent_is_owner_listener(obj);
+ obj->parent_is_owner_listener_func(obj);
}
/* The release function will be invoked by the parent. */
- bt_put(parent);
+ bt_object_put_no_null_check(parent);
} else {
- bt_object_release(obj);
+ bt_object_try_spec_release(obj);
}
}
static inline
-struct bt_object *bt_object_borrow_parent(void *ptr)
+void bt_object_init(struct bt_object *obj, bool is_shared,
+ bt_object_release_func release_func)
{
- struct bt_object *obj = ptr;
-
- return obj ? obj->parent : NULL;
+ 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
-struct bt_object *bt_object_get_parent(void *ptr)
+void bt_object_init_shared(struct bt_object *obj,
+ bt_object_release_func release_func)
{
- return bt_get(bt_object_borrow_parent(ptr));
+ bt_object_init(obj, true, release_func);
}
static inline
-void bt_object_set_parent(void *child_ptr, void *parent)
+void bt_object_init_unique(struct bt_object *obj)
{
- struct bt_object *child = child_ptr;
-
- if (!child) {
- return;
- }
+ bt_object_init(obj, false, NULL);
+}
-#ifdef BT_LOGV
- BT_LOGV("Setting object's parent: addr=%p, parent-addr=%p",
- child_ptr, parent);
-#endif
+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;
+}
- /*
- * 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_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_set_is_shared(struct bt_object *obj, bool is_shared)
+void bt_object_inc_ref_count(struct bt_object *obj)
{
- obj->is_shared = is_shared;
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
+ obj->ref_count++;
+ BT_ASSERT(obj->ref_count != 0);
}
static inline
-void bt_object_init(void *ptr, bt_object_release_func release)
+void bt_object_get_no_null_check(struct bt_object *obj)
{
- struct bt_object *obj = ptr;
+ BT_ASSERT(obj);
+ BT_ASSERT(obj->is_shared);
- obj->release = release;
- obj->parent = NULL;
- bt_object_set_is_shared(obj, true);
- bt_ref_init(&obj->ref_count, generic_release);
+ 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);
+ }
+
+#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_set_parent_is_owner_listener(void *obj,
- bt_object_release_func cb)
+void bt_object_put_no_null_check(struct bt_object *obj)
{
BT_ASSERT(obj);
- ((struct bt_object *) obj)->parent_is_owner_listener = cb;
+ BT_ASSERT(obj->is_shared);
+ BT_ASSERT(obj->ref_count > 0);
+
+#ifdef BT_LOGV
+ BT_LOGV("Decrementing 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
+
+ obj->ref_count--;
+
+ if (obj->ref_count == 0) {
+ BT_ASSERT(obj->release_func);
+ obj->release_func(obj);
+ }
}
#endif /* BABELTRACE_OBJECT_INTERNAL_H */
}
/* Reset reference count to 1 since it could be 0 now */
- bt_obj->ref_count.count = 1;
+ bt_obj->ref_count = 1;
/* Back to the pool */
pool->objects->pdata[pool->size] = obj;
goto error;
}
- bt_object_init(plugin, bt_plugin_destroy);
+ bt_object_init_shared(&plugin->base, bt_plugin_destroy);
plugin->type = type;
/* Create empty array of component classes */
}
BT_LOGD_STR("Creating empty plugin set.");
- bt_object_init(plugin_set, bt_plugin_set_destroy);
+ bt_object_init_shared(&plugin_set->base, bt_plugin_set_destroy);
plugin_set->plugins = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
+++ /dev/null
-#ifndef BABELTRACE_REF_INTERNAL_H
-#define BABELTRACE_REF_INTERNAL_H
-
-/*
- * Babeltrace - Reference Counting
- *
- * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/assert-internal.h>
-
-struct bt_object;
-typedef void (*bt_object_release_func)(struct bt_object *);
-
-struct bt_ref {
- unsigned long count;
- bt_object_release_func release;
-};
-
-static inline
-void bt_ref_init(struct bt_ref *ref, bt_object_release_func release)
-{
- BT_ASSERT(ref);
- ref->count = 1;
- ref->release = release;
-}
-
-static inline
-void bt_ref_get(struct bt_ref *ref)
-{
- BT_ASSERT(ref);
-
- if (unlikely(!ref->release)) {
- return;
- }
-
- ref->count++;
- /* Overflow check. */
- BT_ASSERT(ref->count);
-}
-
-static inline
-void bt_ref_put(struct bt_ref *ref)
-{
- BT_ASSERT(ref);
- /* Only assert if the object has opted-in for reference counting. */
- if (unlikely((--ref->count) == 0 && ref->release)) {
- ref->release((struct bt_object *) ref);
- }
-}
-
-#endif /* BABELTRACE_REF_INTERNAL_H */
clock_class->precision = 1;
clock_class->frequency = freq;
- bt_object_init(clock_class, bt_clock_class_destroy);
+ bt_object_init_shared(&clock_class->base, bt_clock_class_destroy);
if (name) {
ret = bt_clock_class_set_name(clock_class, name);
goto end;
}
- bt_object_init(ret, NULL);
- bt_object_set_is_shared((void *) ret, false);
+ bt_object_init_unique(&ret->base);
ret->clock_class = bt_get(clock_class);
bt_clock_class_freeze(clock_class);
BT_LOGD("Created clock value object: clock-value-addr=%p, "
BT_LOGD("Initializing common event class object: name=\"%s\"",
name);
- bt_object_init(event_class, release_func);
+ bt_object_init_shared_with_parent(&event_class->base, release_func);
event_class->payload_field_type = ft_struct_create_func();
if (!event_class->payload_field_type) {
BT_LOGE_STR("Cannot create event class's initial payload field type object.");
int bt_event_common_initialize(struct bt_event_common *event,
struct bt_event_class_common *event_class,
struct bt_clock_class *init_expected_clock_class,
- bt_object_release_func release_func,
+ bool is_shared_with_parent, bt_object_release_func release_func,
bt_validation_flag_copy_field_type_func field_type_copy_func,
bool must_be_in_trace,
int (*map_clock_classes_func)(struct bt_stream_class_common *stream_class,
* failure, the caller releases the reference to `event` to
* destroy it.
*/
- bt_object_init(event, release_func);
+ if (is_shared_with_parent) {
+ bt_object_init_shared_with_parent(&event->base, release_func);
+ } else {
+ bt_object_init_unique(&event->base);
+ }
if (!stream_class->frozen) {
/*
}
ret = bt_event_common_initialize(BT_TO_COMMON(event),
- BT_TO_COMMON(event_class), NULL, NULL,
+ BT_TO_COMMON(event_class), NULL, false, NULL,
(bt_validation_flag_copy_field_type_func) bt_field_type_copy,
true, NULL,
(create_field_func) bt_field_create_recursive,
goto error;
}
- bt_object_set_is_shared((void *) event, false);
event->clock_values = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
(GDestroyNotify) bt_clock_value_recycle);
goto error;
}
- bt_object_init(field_path, field_path_destroy);
+ bt_object_init_shared(&field_path->base, field_path_destroy);
field_path->root = BT_SCOPE_UNKNOWN;
field_path->indexes = g_array_new(TRUE, FALSE, sizeof(int));
if (!field_path->indexes) {
BT_ASSERT(ft && (ft->id > BT_FIELD_TYPE_ID_UNKNOWN) &&
(ft->id < BT_FIELD_TYPE_ID_NR));
- bt_object_init(ft, release_func);
+ bt_object_init_shared(&ft->base, release_func);
ft->methods = methods;
if (init_bo) {
goto end;
}
- bt_object_init(&iter->base, bt_field_type_enum_iter_destroy);
+ bt_object_init_shared(&iter->base, bt_field_type_enum_iter_destroy);
iter->enumeration_ft = bt_get(ft);
iter->index = -1;
iter->type = iterator_type;
goto end;
}
- bt_object_init(field_wrapper, NULL);
- bt_object_set_is_shared((void *) field_wrapper, false);
+ bt_object_init_unique(&field_wrapper->base);
BT_LOGD("Created empty field wrapper object: addr=%p",
field_wrapper);
goto end;
}
- bt_object_set_is_shared((void *) field, false);
bt_field_type_freeze(type);
end:
if (integer) {
bt_field_common_initialize(BT_TO_COMMON(integer), (void *) type,
- NULL, &bt_field_integer_methods);
+ false, NULL, &bt_field_integer_methods);
BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
integer, type);
} else {
if (enumeration) {
bt_field_common_initialize(
BT_TO_COMMON(BT_TO_COMMON(enumeration)),
- (void *) type, NULL, &bt_field_enumeration_methods);
+ (void *) type, false, NULL,
+ &bt_field_enumeration_methods);
BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
enumeration, type);
} else {
if (floating_point) {
bt_field_common_initialize(BT_TO_COMMON(floating_point),
- (void *) type, NULL, &bt_field_floating_point_methods);
+ (void *) type, false, NULL,
+ &bt_field_floating_point_methods);
BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
floating_point, type);
} else {
BT_HIDDEN
int bt_field_common_structure_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_release_func)
size_t i;
BT_LOGD("Initializing common structure field object: ft-addr=%p", type);
- bt_field_common_initialize(field, type, release_func, methods);
+ bt_field_common_initialize(field, type, is_shared,
+ release_func, methods);
structure->fields = g_ptr_array_new_with_free_func(field_release_func);
g_ptr_array_set_size(structure->fields, structure_type->fields->len);
}
iret = bt_field_common_structure_initialize(BT_TO_COMMON(structure),
- (void *) type, NULL, &bt_field_structure_methods,
+ (void *) type, false, NULL, &bt_field_structure_methods,
(bt_field_common_create_func) bt_field_create_recursive,
(GDestroyNotify) bt_field_destroy_recursive);
if (iret) {
BT_HIDDEN
int bt_field_common_variant_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_release_func)
size_t i;
BT_LOGD("Initializing common variant field object: ft-addr=%p", type);
- bt_field_common_initialize(field, type, release_func, methods);
+ bt_field_common_initialize(field, type, is_shared,
+ release_func, methods);
ret = bt_field_type_common_variant_update_choices(type);
if (ret) {
BT_LOGE("Cannot update common variant field type choices: "
BT_HIDDEN
int bt_field_common_string_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods)
{
int ret = 0;
struct bt_field_common_string *string = BT_FROM_COMMON(field);
BT_LOGD("Initializing common string field object: ft-addr=%p", type);
- bt_field_common_initialize(field, type, release_func, methods);
+ bt_field_common_initialize(field, type, is_shared,
+ release_func, methods);
string->buf = g_array_sized_new(FALSE, FALSE, sizeof(char), 1);
if (!string->buf) {
ret = -1;
}
iret = bt_field_common_variant_initialize(BT_TO_COMMON(variant),
- (void *) type, NULL, &bt_field_variant_methods,
+ (void *) type, false, NULL, &bt_field_variant_methods,
(bt_field_common_create_func) bt_field_create_recursive,
(GDestroyNotify) bt_field_destroy_recursive);
if (iret) {
BT_HIDDEN
int bt_field_common_array_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
bt_field_common_create_func field_create_func,
GDestroyNotify field_destroy_func)
BT_LOGD("Initializing common array field object: ft-addr=%p", type);
BT_ASSERT(type);
- bt_field_common_initialize(field, type, release_func, methods);
+ bt_field_common_initialize(field, type, is_shared,
+ release_func, methods);
array_length = array_type->length;
array->elements = g_ptr_array_sized_new(array_length);
if (!array->elements) {
}
ret = bt_field_common_array_initialize(BT_TO_COMMON(array),
- (void *) type, NULL, &bt_field_array_methods,
+ (void *) type, false, NULL, &bt_field_array_methods,
(bt_field_common_create_func) bt_field_create_recursive,
(GDestroyNotify) bt_field_destroy_recursive);
if (ret) {
BT_HIDDEN
int bt_field_common_sequence_initialize(struct bt_field_common *field,
struct bt_field_type_common *type,
- bt_object_release_func release_func,
+ bool is_shared, bt_object_release_func release_func,
struct bt_field_common_methods *methods,
GDestroyNotify field_destroy_func)
{
BT_LOGD("Initializing common sequence field object: ft-addr=%p", type);
BT_ASSERT(type);
- bt_field_common_initialize(field, type, release_func, methods);
+ bt_field_common_initialize(field, type, is_shared,
+ release_func, methods);
sequence->elements = g_ptr_array_new();
if (!sequence->elements) {
ret = -1;
}
ret = bt_field_common_sequence_initialize(BT_TO_COMMON(sequence),
- (void *) type, NULL, &bt_field_sequence_methods,
+ (void *) type, false, NULL, &bt_field_sequence_methods,
(GDestroyNotify) bt_field_destroy_recursive);
if (ret) {
BT_PUT(sequence);
if (string) {
bt_field_common_string_initialize(BT_TO_COMMON(string),
- (void *) type, NULL, &bt_field_string_methods);
+ (void *) type, false, NULL, &bt_field_string_methods);
BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
string, type);
} else {
goto end;
}
- bt_object_init(packet, (bt_object_release_func) bt_packet_recycle);
+ bt_object_init_shared(&packet->base,
+ (bt_object_release_func) bt_packet_recycle);
packet->stream = bt_get(stream);
if (trace->common.packet_header_field_type) {
{
BT_LOGD("Initializing common stream class object: name=\"%s\"", name);
- bt_object_init(stream_class, release_func);
+ bt_object_init_shared_with_parent(&stream_class->base, release_func);
stream_class->name = g_string_new(name);
stream_class->event_classes = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!stream_class->event_classes) {
BT_LOGE_STR("Failed to allocate a GPtrArray.");
goto error;
*event_id = stream_class->next_event_id;
}
- bt_object_set_parent(event_class, stream_class);
+ bt_object_set_parent(&event_class->base, &stream_class->base);
if (trace) {
/*
int ret = 0;
struct bt_trace_common *trace = NULL;
- bt_object_init(stream, release_func);
+ bt_object_init_shared_with_parent(&stream->base, release_func);
if (!stream_class) {
BT_LOGW_STR("Invalid parameter: stream class is NULL.");
* Acquire reference to parent since stream will become publicly
* reachable; it needs its parent to remain valid.
*/
- bt_object_set_parent(stream, trace);
+ bt_object_set_parent(&stream->base, &trace->base);
stream->stream_class = stream_class;
stream->id = (int64_t) id;
stream->destroy_listeners = g_array_new(FALSE, TRUE,
BT_LOGD_STR("Initializing common trace object.");
trace->native_byte_order = BT_BYTE_ORDER_UNSPECIFIED;
- bt_object_init(trace, release_func);
+ bt_object_init_shared_with_parent(&trace->base, release_func);
trace->clock_classes = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
if (!trace->clock_classes) {
}
trace->streams = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!trace->streams) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
trace->stream_classes = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!trace->stream_classes) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
}
- bt_object_set_parent(stream_class, trace);
+ bt_object_set_parent(&stream_class->base, &trace->base);
g_ptr_array_add(trace->stream_classes, stream_class);
/*
end:
if (ret) {
- bt_object_set_parent(stream_class, NULL);
+ bt_object_set_parent(&stream_class->base, NULL);
if (ec_validation_outputs) {
for (i = 0; i < event_class_count; i++) {
goto error;
}
- bt_object_init(clock, bt_ctf_clock_destroy);
+ bt_object_init_shared(&clock->base, bt_ctf_clock_destroy);
clock->value = 0;
/* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */
ret = bt_event_common_initialize(BT_TO_COMMON(event),
BT_TO_COMMON(event_class), expected_clock_class,
- bt_ctf_event_destroy,
+ true, bt_ctf_event_destroy,
(bt_validation_flag_copy_field_type_func)
bt_ctf_field_type_copy,
false, map_clock_classes_func,
{
BT_ASSERT(event);
return (struct bt_ctf_stream *)
- bt_object_borrow_parent(BT_TO_COMMON(event));
+ bt_object_borrow_parent(&BT_TO_COMMON(event)->base);
}
struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event)
if (integer) {
bt_field_common_initialize(BT_TO_COMMON(integer), (void *) type,
+ true,
(bt_object_release_func) bt_ctf_field_integer_destroy,
&bt_ctf_field_integer_methods);
integer->common.spec.writer.serialize_func =
bt_field_common_initialize(BT_TO_COMMON(enumeration),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_enumeration_destroy_recursive,
&bt_ctf_field_enumeration_methods);
enumeration->container = (void *) bt_ctf_field_create(
if (floating_point) {
bt_field_common_initialize(BT_TO_COMMON(floating_point),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_floating_point_destroy,
&bt_ctf_field_floating_point_methods);
floating_point->common.spec.writer.serialize_func =
iret = bt_field_common_structure_initialize(BT_TO_COMMON(structure),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_structure_destroy_recursive,
&bt_ctf_field_structure_methods,
(bt_field_common_create_func) bt_ctf_field_create,
bt_field_common_variant_initialize(BT_TO_COMMON(BT_TO_COMMON(variant)),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_variant_destroy_recursive,
&bt_ctf_field_variant_methods,
(bt_field_common_create_func) bt_ctf_field_create,
ret = bt_field_common_array_initialize(BT_TO_COMMON(array),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_array_destroy_recursive,
&bt_ctf_field_array_methods,
(bt_field_common_create_func) bt_ctf_field_create,
if (sequence) {
bt_field_common_sequence_initialize(BT_TO_COMMON(sequence),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_sequence_destroy_recursive,
&bt_ctf_field_sequence_methods,
(GDestroyNotify) bt_put);
if (string) {
bt_field_common_string_initialize(BT_TO_COMMON(string),
(void *) type,
- (bt_object_release_func)
+ true, (bt_object_release_func)
bt_ctf_field_string_destroy,
&bt_ctf_field_string_methods);
string->common.spec.writer.serialize_func =
goto end;
}
- trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
+ trace = (struct bt_ctf_trace *)
+ bt_object_get_parent(&stream->common.base);
+
for (i = 0; i < 16; i++) {
struct bt_ctf_field *uuid_element =
bt_ctf_field_array_get_field(uuid_field, i);
static
void release_event(struct bt_ctf_event *event)
{
- if (bt_object_get_ref_count(event)) {
+ if (bt_object_get_ref_count(&event->common.base)) {
/*
* The event is being orphaned, but it must guarantee the
* existence of its event class for the duration of its
bt_get(event->common.class);
BT_PUT(event->common.base.parent);
} else {
- bt_object_release(event);
+ bt_object_try_spec_release(&event->common.base);
}
}
}
stream->pos.fd = -1;
- writer = (struct bt_ctf_writer *) bt_object_get_parent(trace);
+ writer = (struct bt_ctf_writer *)
+ bt_object_get_parent(&trace->common.base);
stream->last_ts_end = -1ULL;
BT_LOGD("CTF writer stream object belongs writer's trace: "
"writer-addr=%p", writer);
goto end;
}
- bt_object_set_parent(event, stream);
+ bt_object_set_parent(&event->common.base, &stream->common.base);
BT_LOGV_STR("Automatically populating the header of the event to append.");
ret = auto_populate_event_header(stream, event);
if (ret) {
* Orphan the event; we were not successful in associating it to
* a stream.
*/
- bt_object_set_parent(event, NULL);
-
+ bt_object_set_parent(&event->common.base, NULL);
return ret;
}
goto end;
}
- trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
+ trace = (struct bt_ctf_trace *)
+ bt_object_get_parent(&stream->common.base);
if (!field) {
if (trace->common.packet_header_field_type) {
metadata_path = g_build_filename(path, "metadata", NULL);
- bt_object_init(writer, bt_ctf_writer_destroy);
+ bt_object_init_shared(&writer->base, bt_ctf_writer_destroy);
writer->path = g_string_new(path);
if (!writer->path) {
goto error_destroy;
goto error_destroy;
}
- bt_object_set_parent(writer->trace, writer);
+ bt_object_set_parent(&writer->trace->common.base, &writer->base);
bt_put(writer->trace);
/* Default to little-endian */
}
}
- bt_object_release(writer->trace);
+ bt_object_try_spec_release(&writer->trace->common.base);
g_free(writer);
}
goto error;
}
- bt_object_init(cc_prio_map, bt_clock_class_priority_map_destroy);
+ bt_object_init_shared(&cc_prio_map->base,
+ bt_clock_class_priority_map_destroy);
cc_prio_map->entries = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
if (!cc_prio_map->entries) {
{
int ret = 0;
- bt_object_init(class, bt_component_class_destroy);
+ bt_object_init_shared(&class->base, bt_component_class_destroy);
class->type = type;
class->name = g_string_new(name);
if (!class->name) {
* bt_put(): the reference count would go from 1 to 0 again and
* this function would be called again.
*/
- obj->ref_count.count++;
+ obj->ref_count++;
component = container_of(obj, struct bt_component, base);
BT_LOGD("Destroying component: addr=%p, name=\"%s\", graph-addr=%p",
component, bt_component_get_name(component),
goto end;
}
- bt_object_init(component, bt_component_destroy);
+ bt_object_init_shared_with_parent(&component->base,
+ bt_component_destroy);
component->class = bt_get(component_class);
component->destroy = component_destroy_funcs[type];
component->name = g_string_new(name);
}
component->input_ports = g_ptr_array_new_with_free_func(
- bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!component->input_ports) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
status = BT_COMPONENT_STATUS_NOMEM;
}
component->output_ports = g_ptr_array_new_with_free_func(
- bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!component->output_ports) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
status = BT_COMPONENT_STATUS_NOMEM;
void bt_component_set_graph(struct bt_component *component,
struct bt_graph *graph)
{
- bt_object_set_parent(component, graph ? &graph->base : NULL);
+ bt_object_set_parent(&component->base,
+ graph ? &graph->base : NULL);
}
struct bt_graph *bt_component_borrow_graph(struct bt_component *component)
static
void bt_connection_try_remove_from_graph(struct bt_connection *connection)
{
- void *graph = bt_object_borrow_parent(&connection->base);
+ void *graph = (void *) bt_object_borrow_parent(&connection->base);
- if (connection->base.ref_count.count > 0 ||
+ if (connection->base.ref_count > 0 ||
connection->downstream_port ||
connection->upstream_port ||
connection->iterators->len > 0) {
goto end;
}
- bt_object_init(connection, bt_connection_destroy);
- bt_object_set_parent_is_owner_listener(connection,
+ bt_object_init_shared_with_parent(&connection->base,
+ bt_connection_destroy);
+ bt_object_set_parent_is_owner_listener_func(&connection->base,
bt_connection_parent_is_owner);
connection->iterators = g_ptr_array_new();
if (!connection->iterators) {
bt_port_set_connection(upstream_port, connection);
BT_LOGD_STR("Setting downstream port's connection.");
bt_port_set_connection(downstream_port, connection);
- bt_object_set_parent(connection, &graph->base);
+ bt_object_set_parent(&connection->base, &graph->base);
BT_LOGD("Created connection: "
"graph-addr=%p, upstream-port-addr=%p, uptream-port-name=\"%s\", "
"downstream-port-addr=%p, downstream-port-name=\"%s\", "
* ensures that this function is not called two times.
*/
BT_LOGD("Destroying graph: addr=%p", graph);
- obj->ref_count.count++;
+ obj->ref_count++;
/*
* Cancel the graph to disallow some operations, like creating
goto end;
}
- bt_object_init(graph, bt_graph_destroy);
-
- graph->connections = g_ptr_array_new_with_free_func(bt_object_release);
+ bt_object_init_shared(&graph->base, bt_graph_destroy);
+ graph->connections = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_object_try_spec_release);
if (!graph->connections) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
- graph->components = g_ptr_array_new_with_free_func(bt_object_release);
+ graph->components = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_object_try_spec_release);
if (!graph->components) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
BT_ASSERT(graph);
BT_ASSERT(component);
- BT_ASSERT(component->base.ref_count.count == 0);
+ BT_ASSERT(component->base.ref_count == 0);
BT_ASSERT(bt_component_borrow_graph(component) == graph);
init_can_consume = graph->can_consume;
}
/*
- * This calls bt_object_release() on the component, and since
- * its reference count is 0, its destructor is called. Its
+ * This calls bt_object_try_spec_release() on the component, and
+ * since its reference count is 0, its destructor is called. Its
* destructor calls the user's finalization method (if set).
*/
g_ptr_array_remove(graph->components, component);
* reference count would go from 1 to 0 again and this function
* would be called again.
*/
- obj->ref_count.count++;
+ obj->ref_count++;
iterator = (void *) obj;
BT_LOGD("Destroying private connection notification iterator object: addr=%p",
iterator);
enum bt_notification_iterator_type type,
bt_object_release_func destroy)
{
- bt_object_init(iterator, destroy);
+ bt_object_init_shared(&iterator->base, destroy);
iterator->type = type;
}
BT_ASSERT(type >= 0 && type < BT_NOTIFICATION_TYPE_NR);
notification->type = type;
init_seq_num(notification);
- bt_object_init(¬ification->base, release);
+ bt_object_init_shared(¬ification->base, release);
notification->graph = graph;
if (graph) {
parent_component, bt_component_get_name(parent_component),
bt_port_type_string(type), name);
- bt_object_init(port, bt_port_destroy);
+ bt_object_init_shared_with_parent(&port->base, bt_port_destroy);
port->name = g_string_new(name);
if (!port->name) {
BT_LOGE_STR("Failed to allocate one GString.");
port->type = type;
port->user_data = user_data;
- bt_object_set_parent(port, &parent_component->base);
+ bt_object_set_parent(&port->base, &parent_component->base);
BT_LOGD("Created port for component: "
"comp-addr=%p, comp-name=\"%s\", port-type=%s, "
"port-name=\"%s\", port-addr=%p",
struct bt_component *bt_port_get_component(struct bt_port *port)
{
- return (struct bt_component *) bt_object_get_parent(port);
+ return (struct bt_component *) bt_object_get_parent(&port->base);
}
struct bt_private_connection *bt_private_port_get_private_connection(
goto end;
}
- comp = (void *) bt_object_get_parent(port);
+ comp = (void *) bt_object_get_parent(&port->base);
if (!comp) {
BT_LOGV("Port already removed from its component: "
"port-addr=%p, port-name=\"%s\", ",
goto end;
}
- bt_object_init(query_exec, bt_query_executor_destroy);
+ bt_object_init_shared(&query_exec->base,
+ bt_query_executor_destroy);
BT_LOGD("Created query executor: addr=%p", query_exec);
end:
#include <glib.h>
#include <babeltrace/common-internal.h>
#include <babeltrace/lib-logging-internal.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/values-internal.h>
#include <babeltrace/object-pool-internal.h>
#include <babeltrace/ctf-ir/field-types-internal.h>
static inline void format_connection(char **buf_ch, bool extended,
const char *prefix, struct bt_connection *connection);
-static inline void format_ref_count(char **buf_ch, bool extended,
+static inline void format_object(char **buf_ch, bool extended,
const char *prefix, struct bt_object *obj)
{
- BUF_APPEND(", %sref-count=%lu", prefix, obj->ref_count.count);
+ BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count);
}
static inline void format_object_pool(char **buf_ch, bool extended,
return;
}
- trace = (void *) bt_object_borrow_parent(stream);
+ trace = (void *) bt_object_borrow_parent(&stream->base);
if (!trace) {
return;
}
BUF_APPEND(", %sstream-addr=%p", PRFIELD(stream));
SET_TMP_PREFIX("stream-");
format_stream(buf_ch, false, tmp_prefix, stream);
- trace = (struct bt_trace *) bt_object_borrow_parent(stream);
+ trace = (struct bt_trace *) bt_object_borrow_parent(&stream->common.base);
if (!trace) {
return;
}
switch (cat) {
case CAT_DEFAULT:
switch (*fmt_ch) {
- case 'r':
- format_ref_count(buf_ch, extended, prefix, obj);
- break;
case 'F':
format_field_type(buf_ch, extended, prefix, obj);
break;
case 'o':
format_object_pool(buf_ch, extended, prefix, obj);
break;
+ case 'O':
+ format_object(buf_ch, extended, prefix, obj);
+ break;
default:
abort();
}
goto error;
}
- bt_object_init(shared_lib_handle, bt_plugin_so_shared_lib_handle_destroy);
+ bt_object_init_shared(&shared_lib_handle->base,
+ bt_plugin_so_shared_lib_handle_destroy);
if (!path) {
goto end;
#include <babeltrace/lib-logging-internal.h>
#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/object-internal.h>
void *bt_get(void *ptr)
}
BT_ASSERT_PRE(obj->is_shared, "Object is not shared: addr=%p", obj);
-
- if (unlikely(!obj->ref_count.release)) {
- goto end;
- }
-
- if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) {
- BT_LOGV("Incrementing object's parent's reference count: "
- "addr=%p, parent-addr=%p", ptr, obj->parent);
- bt_get(obj->parent);
- }
- BT_LOGV("Incrementing object's reference count: %lu -> %lu: "
- "addr=%p, cur-count=%lu, new-count=%lu",
- obj->ref_count.count, obj->ref_count.count + 1,
- ptr,
- obj->ref_count.count, obj->ref_count.count + 1);
- bt_ref_get(&obj->ref_count);
+ bt_object_get_no_null_check(obj);
end:
- return obj;
+ return ptr;
}
void bt_put(void *ptr)
}
BT_ASSERT_PRE(obj->is_shared, "Object is not shared: addr=%p", obj);
-
- if (unlikely(!obj->ref_count.release)) {
- return;
- }
-
- if (BT_LOG_ON_WARN && unlikely(bt_object_get_ref_count(obj) == 0)) {
- BT_LOGW("Decrementing a reference count set to 0: addr=%p",
- ptr);
- }
-
- BT_LOGV("Decrementing object's reference count: %lu -> %lu: "
- "addr=%p, cur-count=%lu, new-count=%lu",
- obj->ref_count.count, obj->ref_count.count - 1,
- ptr,
- obj->ref_count.count, obj->ref_count.count - 1);
- bt_ref_put(&obj->ref_count);
+ 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);
}
bt_bool frozen;
};
+static
+void bt_value_null_instance_release_func(struct bt_object *obj)
+{
+ BT_LOGW("Releasing the null value singleton: addr=%p", obj);
+}
+
static
struct bt_value bt_value_null_instance = {
.base = {
- .ref_count = {
- .count = 1,
- .release = NULL,
- },
- .release = NULL,
- .parent = NULL,
.is_shared = true,
+ .ref_count = 1,
+ .release_func = bt_value_null_instance_release_func,
+ .spec_release_func = NULL,
+ .parent_is_owner_listener_func = NULL,
+ .parent = NULL,
},
.type = BT_VALUE_TYPE_NULL,
.frozen = BT_TRUE,
static
struct bt_value bt_value_create_base(enum bt_value_type type)
{
- struct bt_value base;
+ struct bt_value value;
- base.type = type;
- base.frozen = BT_FALSE;
- bt_object_init(&base, bt_value_destroy);
- return base;
+ value.type = type;
+ value.frozen = BT_FALSE;
+ bt_object_init_shared(&value.base, bt_value_destroy);
+ return value;
}
struct bt_value *bt_value_bool_create_init(bt_bool val)
init_weak_refs(tc1, &weak_tc1, &weak_sc1, &weak_sc2, &weak_ec1,
&weak_ec2, &weak_ec3);
- ok(bt_object_get_ref_count(weak_sc1) == 0,
+ ok(bt_object_get_ref_count((void *) weak_sc1) == 0,
"Initial SC1 reference count is 0");
- ok(bt_object_get_ref_count(weak_sc2) == 0,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 0,
"Initial SC2 reference count is 0");
- ok(bt_object_get_ref_count(weak_ec1) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec1) == 0,
"Initial EC1 reference count is 0");
- ok(bt_object_get_ref_count(weak_ec2) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec2) == 0,
"Initial EC2 reference count is 0");
- ok(bt_object_get_ref_count(weak_ec3) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 0,
"Initial EC3 reference count is 0");
/* User A has ownership of the trace. */
BT_MOVE(user_a.tc, tc1);
- ok(bt_object_get_ref_count(user_a.tc) == 1,
+ ok(bt_object_get_ref_count((void *) user_a.tc) == 1,
"TC1 reference count is 1");
/* User A acquires a reference to SC2 from TC1. */
user_a.sc = bt_trace_get_stream_class_by_index(user_a.tc, 1);
ok(user_a.sc, "User A acquires SC2 from TC1");
- ok(bt_object_get_ref_count(weak_tc1) == 2,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
"TC1 reference count is 2");
- ok(bt_object_get_ref_count(weak_sc2) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 1,
"SC2 reference count is 1");
/* User A acquires a reference to EC3 from SC2. */
user_a.ec = bt_stream_class_get_event_class_by_index(user_a.sc, 0);
ok(user_a.ec, "User A acquires EC3 from SC2");
- ok(bt_object_get_ref_count(weak_tc1) == 2,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
"TC1 reference count is 2");
- ok(bt_object_get_ref_count(weak_sc2) == 2,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 2,
"SC2 reference count is 2");
- ok(bt_object_get_ref_count(weak_ec3) == 1,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 1,
"EC3 reference count is 1");
/* User A releases its reference to SC2. */
* We keep the pointer to SC2 around to validate its reference
* count.
*/
- ok(bt_object_get_ref_count(weak_tc1) == 2,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
"TC1 reference count is 2");
- ok(bt_object_get_ref_count(weak_sc2) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 1,
"SC2 reference count is 1");
- ok(bt_object_get_ref_count(weak_ec3) == 1,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 1,
"EC3 reference count is 1");
/* User A releases its reference to TC1. */
* We keep the pointer to TC1 around to validate its reference
* count.
*/
- ok(bt_object_get_ref_count(weak_tc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 1,
"TC1 reference count is 1");
- ok(bt_object_get_ref_count(weak_sc2) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 1,
"SC2 reference count is 1");
- ok(bt_object_get_ref_count(weak_ec3) == 1,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 1,
"EC3 reference count is 1");
/* User B acquires a reference to SC1. */
diag("User B acquires a reference to SC1");
user_b.sc = bt_get(weak_sc1);
- ok(bt_object_get_ref_count(weak_tc1) == 2,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 2,
"TC1 reference count is 2");
- ok(bt_object_get_ref_count(weak_sc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc1) == 1,
"SC1 reference count is 1");
/* User C acquires a reference to EC1. */
diag("User C acquires a reference to EC1");
user_c.ec = bt_stream_class_get_event_class_by_index(user_b.sc, 0);
- ok(bt_object_get_ref_count(weak_ec1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_ec1) == 1,
"EC1 reference count is 1");
- ok(bt_object_get_ref_count(weak_sc1) == 2,
+ ok(bt_object_get_ref_count((void *) weak_sc1) == 2,
"SC1 reference count is 2");
/* User A releases its reference on EC3. */
diag("User A releases its reference on EC3");
BT_PUT(user_a.ec);
- ok(bt_object_get_ref_count(weak_ec3) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 0,
"EC3 reference count is 1");
- ok(bt_object_get_ref_count(weak_sc2) == 0,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 0,
"SC2 reference count is 0");
- ok(bt_object_get_ref_count(weak_tc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 1,
"TC1 reference count is 1");
/* User B releases its reference on SC1. */
diag("User B releases its reference on SC1");
BT_PUT(user_b.sc);
- ok(bt_object_get_ref_count(weak_sc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc1) == 1,
"SC1 reference count is 1");
/*
* User C is the sole owner of an object and is keeping the whole
* trace hierarchy "alive" by holding a reference to EC1.
*/
- ok(bt_object_get_ref_count(weak_tc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_tc1) == 1,
"TC1 reference count is 1");
- ok(bt_object_get_ref_count(weak_sc1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_sc1) == 1,
"SC1 reference count is 1");
- ok(bt_object_get_ref_count(weak_sc2) == 0,
+ ok(bt_object_get_ref_count((void *) weak_sc2) == 0,
"SC2 reference count is 0");
- ok(bt_object_get_ref_count(weak_ec1) == 1,
+ ok(bt_object_get_ref_count((void *) weak_ec1) == 1,
"EC1 reference count is 1");
- ok(bt_object_get_ref_count(weak_ec2) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec2) == 0,
"EC2 reference count is 0");
- ok(bt_object_get_ref_count(weak_ec3) == 0,
+ ok(bt_object_get_ref_count((void *) weak_ec3) == 0,
"EC3 reference count is 0");
/* Reclaim last reference held by User C. */