#include <babeltrace/ctf-ir/clock-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ctf-ir/ref.h>
#include <babeltrace/ctf-writer/writer-internal.h>
#include <babeltrace/compiler.h>
#include <inttypes.h>
static
-void bt_ctf_clock_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_clock_destroy(struct bt_ref *ref);
BT_HIDDEN
struct bt_ctf_clock *_bt_ctf_clock_create(void)
clock->precision = 1;
clock->frequency = 1000000000;
- bt_ctf_ref_init(&clock->ref_count);
+ bt_ctf_base_init(clock, bt_ctf_clock_destroy);
end:
return clock;
}
clock->uuid_set = 1;
return clock;
error_destroy:
- bt_ctf_clock_destroy(&clock->ref_count);
+ bt_ctf_clock_destroy(&clock->base.ref_count);
error:
return NULL;
}
void bt_ctf_clock_get(struct bt_ctf_clock *clock)
{
- if (!clock) {
- return;
- }
-
- bt_ctf_ref_get(&clock->ref_count);
+ bt_ctf_get(clock);
}
void bt_ctf_clock_put(struct bt_ctf_clock *clock)
{
- if (!clock) {
- return;
- }
-
- bt_ctf_ref_put(&clock->ref_count, bt_ctf_clock_destroy);
+ bt_ctf_put(clock);
}
BT_HIDDEN
}
static
-void bt_ctf_clock_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_clock_destroy(struct bt_ref *ref)
{
struct bt_ctf_clock *clock;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- clock = container_of(ref, struct bt_ctf_clock, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ clock = container_of(base, struct bt_ctf_clock, base);
if (clock->name) {
g_string_free(clock->name, TRUE);
}
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-ir/event-fields-internal.h>
#include <babeltrace/ctf-ir/event-types-internal.h>
+#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ctf-ir/ref.h>
#include <babeltrace/compiler.h>
#define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT)
struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *);
static
-void bt_ctf_field_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_destroy(struct bt_ref *);
static
void bt_ctf_field_integer_destroy(struct bt_ctf_field *);
static
/* The type's declaration can't change after this point */
bt_ctf_field_type_freeze(type);
bt_ctf_field_type_get(type);
- bt_ctf_ref_init(&field->ref_count);
+ bt_ctf_base_init(field, bt_ctf_field_destroy);
field->type = type;
error:
return field;
void bt_ctf_field_get(struct bt_ctf_field *field)
{
- if (field) {
- bt_ctf_ref_get(&field->ref_count);
- }
+ bt_ctf_get(field);
}
void bt_ctf_field_put(struct bt_ctf_field *field)
{
- if (field) {
- bt_ctf_ref_put(&field->ref_count, bt_ctf_field_destroy);
- }
+ bt_ctf_put(field);
}
struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field)
}
static
-void bt_ctf_field_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_destroy(struct bt_ref *ref)
{
struct bt_ctf_field *field;
+ struct bt_ctf_base *base;
struct bt_ctf_field_type *type;
enum ctf_type_id type_id;
return;
}
- field = container_of(ref, struct bt_ctf_field, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ field = container_of(base, struct bt_ctf_field, base);
type = field->type;
type_id = bt_ctf_field_type_get_type_id(type);
if (type_id <= CTF_TYPE_UNKNOWN ||
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-ir/event-types-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/ctf-ir/clock.h>
#include <babeltrace/ctf-writer/writer-internal.h>
#include <babeltrace/compiler.h>
};
static
-void bt_ctf_field_type_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_destroy(struct bt_ref *);
static
-void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_structure_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_variant_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_array_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_sequence_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *);
static
-void bt_ctf_field_type_string_destroy(struct bt_ctf_ref *);
+void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type *);
static
-void (* const type_destroy_funcs[])(struct bt_ctf_ref *) = {
+void (* const type_destroy_funcs[])(struct bt_ctf_field_type *) = {
[CTF_TYPE_INTEGER] = bt_ctf_field_type_integer_destroy,
[CTF_TYPE_ENUM] =
bt_ctf_field_type_enumeration_destroy,
assert(type && (type_id > CTF_TYPE_UNKNOWN) &&
(type_id < NR_CTF_TYPES));
- bt_ctf_ref_init(&type->ref_count);
+ bt_ctf_base_init(type, bt_ctf_field_type_destroy);
type->freeze = type_freeze_funcs[type_id];
type->serialize = type_serialize_funcs[type_id];
}
static
-void bt_ctf_field_type_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_destroy(struct bt_ref *ref)
{
struct bt_ctf_field_type *type;
+ struct bt_ctf_base *base;
enum ctf_type_id type_id;
if (!ref) {
return;
}
- type = container_of(ref, struct bt_ctf_field_type, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ type = container_of(base, struct bt_ctf_field_type, base);
type_id = type->declaration->id;
if (type_id <= CTF_TYPE_UNKNOWN ||
type_id >= NR_CTF_TYPES) {
return;
}
- type_destroy_funcs[type_id](ref);
+ type_destroy_funcs[type_id](type);
}
BT_HIDDEN
void bt_ctf_field_type_get(struct bt_ctf_field_type *type)
{
- if (!type) {
- return;
- }
-
- bt_ctf_ref_get(&type->ref_count);
+ bt_ctf_get(type);
}
void bt_ctf_field_type_put(struct bt_ctf_field_type *type)
{
- if (!type) {
- return;
- }
-
- bt_ctf_ref_put(&type->ref_count, bt_ctf_field_type_destroy);
+ bt_ctf_put(type);
}
BT_HIDDEN
}
static
-void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_integer *integer;
+ struct bt_ctf_field_type_integer *integer =
+ (struct bt_ctf_field_type_integer *) type;
- if (!ref) {
+ if (!type) {
return;
}
- integer = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_integer, parent);
if (integer->mapped_clock) {
bt_ctf_clock_put(integer->mapped_clock);
}
}
static
-void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_enumeration *enumeration;
+ struct bt_ctf_field_type_enumeration *enumeration =
+ (struct bt_ctf_field_type_enumeration *) type;
- if (!ref) {
+ if (!type) {
return;
}
- enumeration = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_enumeration, parent);
g_ptr_array_free(enumeration->entries, TRUE);
bt_ctf_field_type_put(enumeration->container);
g_free(enumeration);
}
static
-void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_floating_point *floating_point;
+ struct bt_ctf_field_type_floating_point *floating_point =
+ (struct bt_ctf_field_type_floating_point *) type;
- if (!ref) {
+ if (!type) {
return;
}
- floating_point = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_floating_point, parent);
g_free(floating_point);
}
static
-void bt_ctf_field_type_structure_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_structure *structure;
+ struct bt_ctf_field_type_structure *structure =
+ (struct bt_ctf_field_type_structure *) type;
- if (!ref) {
+ if (!type) {
return;
}
- structure = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_structure, parent);
g_ptr_array_free(structure->fields, TRUE);
g_hash_table_destroy(structure->field_name_to_index);
g_free(structure);
}
static
-void bt_ctf_field_type_variant_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_variant *variant;
+ struct bt_ctf_field_type_variant *variant =
+ (struct bt_ctf_field_type_variant *) type;
- if (!ref) {
+ if (!type) {
return;
}
- variant = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_variant, parent);
g_ptr_array_free(variant->fields, TRUE);
g_hash_table_destroy(variant->field_name_to_index);
g_string_free(variant->tag_name, TRUE);
}
static
-void bt_ctf_field_type_array_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_array *array;
+ struct bt_ctf_field_type_array *array =
+ (struct bt_ctf_field_type_array *) type;
- if (!ref) {
+ if (!type) {
return;
}
- array = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_array, parent);
bt_ctf_field_type_put(array->element_type);
g_free(array);
}
static
-void bt_ctf_field_type_sequence_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_sequence *sequence;
+ struct bt_ctf_field_type_sequence *sequence =
+ (struct bt_ctf_field_type_sequence *) type;
- if (!ref) {
+ if (!type) {
return;
}
- sequence = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_sequence, parent);
bt_ctf_field_type_put(sequence->element_type);
g_string_free(sequence->length_field_name, TRUE);
bt_ctf_field_path_destroy(sequence->length_field_path);
}
static
-void bt_ctf_field_type_string_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type *type)
{
- struct bt_ctf_field_type_string *string;
+ struct bt_ctf_field_type_string *string =
+ (struct bt_ctf_field_type_string *) type;
- if (!ref) {
+ if (!type) {
return;
}
- string = container_of(
- container_of(ref, struct bt_ctf_field_type, ref_count),
- struct bt_ctf_field_type_string, parent);
g_free(string);
}
#include <babeltrace/ctf-ir/stream-class-internal.h>
#include <babeltrace/ctf-ir/trace-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ctf-ir/ref.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/compiler.h>
static
-void bt_ctf_event_class_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_event_class_destroy(struct bt_ref *ref);
static
-void bt_ctf_event_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_event_destroy(struct bt_ref *ref);
static
int set_integer_field_value(struct bt_ctf_field *field, uint64_t value);
goto error;
}
- bt_ctf_ref_init(&event_class->ref_count);
+ bt_ctf_base_init(event_class, bt_ctf_event_class_destroy);
event_class->fields = bt_ctf_field_type_structure_create();
if (!event_class->fields) {
goto error;
void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class)
{
- if (!event_class) {
- return;
- }
-
- bt_ctf_ref_get(&event_class->ref_count);
+ bt_ctf_get(event_class);
}
void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class)
{
- if (!event_class) {
- return;
- }
-
- bt_ctf_ref_put(&event_class->ref_count, bt_ctf_event_class_destroy);
+ bt_ctf_put(event_class);
}
BT_HIDDEN
goto end;
}
- bt_ctf_ref_init(&event->ref_count);
+ bt_ctf_base_init(event, bt_ctf_event_destroy);
bt_ctf_event_class_get(event_class);
bt_ctf_event_class_freeze(event_class);
event->event_class = event_class;
return event;
error_destroy:
if (event) {
- bt_ctf_event_destroy(&event->ref_count);
+ bt_ctf_event_destroy(&event->base.ref_count);
}
return NULL;
void bt_ctf_event_get(struct bt_ctf_event *event)
{
- if (!event) {
- return;
- }
-
- bt_ctf_ref_get(&event->ref_count);
+ bt_ctf_get(event);
}
void bt_ctf_event_put(struct bt_ctf_event *event)
{
- if (!event) {
- return;
- }
-
- bt_ctf_ref_put(&event->ref_count, bt_ctf_event_destroy);
+ bt_ctf_put(event);
}
static
-void bt_ctf_event_class_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_event_class_destroy(struct bt_ref *ref)
{
struct bt_ctf_event_class *event_class;
+ struct bt_ctf_base *base;
if (!ref) {
return;
* Don't call put() on the stream class. See comment in
* bt_ctf_event_class_set_stream_class for explanation.
*/
- event_class = container_of(ref, struct bt_ctf_event_class, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ event_class = container_of(base, struct bt_ctf_event_class, base);
if (event_class->attributes) {
bt_ctf_attributes_destroy(event_class->attributes);
}
}
static
-void bt_ctf_event_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_event_destroy(struct bt_ref *ref)
{
struct bt_ctf_event *event;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- event = container_of(ref, struct bt_ctf_event,
- ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ event = container_of(base, struct bt_ctf_event, base);
if (event->event_class) {
bt_ctf_event_class_put(event->event_class);
}
goto error;
}
- bt_ctf_ref_init(©->ref_count);
+ bt_ctf_base_init(copy, bt_ctf_event_destroy);
copy->event_class = event->event_class;
bt_ctf_event_class_get(copy->event_class);
copy->stream = event->stream;
#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/compiler.h>
#include <babeltrace/align.h>
static
-void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_stream_class_destroy(struct bt_ref *ref);
static
int init_event_header(struct bt_ctf_stream_class *stream_class);
static
goto error_destroy;
}
- bt_ctf_ref_init(&stream_class->ref_count);
+ bt_ctf_base_init(stream_class, bt_ctf_stream_class_destroy);
return stream_class;
error_destroy:
- bt_ctf_stream_class_destroy(&stream_class->ref_count);
+ bt_ctf_stream_class_destroy(&stream_class->base.ref_count);
stream_class = NULL;
error:
return stream_class;
void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
{
- if (!stream_class) {
- return;
- }
-
- bt_ctf_ref_get(&stream_class->ref_count);
+ bt_ctf_get(stream_class);
}
void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
{
- if (!stream_class) {
- return;
- }
-
- bt_ctf_ref_put(&stream_class->ref_count, bt_ctf_stream_class_destroy);
+ bt_ctf_put(stream_class);
}
BT_HIDDEN
}
static
-void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_stream_class_destroy(struct bt_ref *ref)
{
struct bt_ctf_stream_class *stream_class;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- stream_class = container_of(ref, struct bt_ctf_stream_class, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ stream_class = container_of(base, struct bt_ctf_stream_class, base);
bt_ctf_clock_put(stream_class->clock);
if (stream_class->event_classes) {
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/ctf-ir/stream-internal.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
+#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/compiler.h>
#include <babeltrace/align.h>
#include <babeltrace/ctf/ctf-index.h>
static
-void bt_ctf_stream_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_stream_destroy(struct bt_ref *ref);
static
int set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t);
/* A stream has no ownership of its trace (weak ptr) */
stream->trace = trace;
- bt_ctf_ref_init(&stream->ref_count);
+ bt_ctf_base_init(stream, bt_ctf_stream_destroy);
stream->packet_context = bt_ctf_field_create(
stream_class->packet_context_type);
if (!stream->packet_context) {
end:
return stream;
error_destroy:
- bt_ctf_stream_destroy(&stream->ref_count);
+ bt_ctf_stream_destroy(&stream->base.ref_count);
return NULL;
}
void bt_ctf_stream_get(struct bt_ctf_stream *stream)
{
- if (!stream) {
- return;
- }
-
- bt_ctf_ref_get(&stream->ref_count);
+ bt_ctf_get(stream);
}
void bt_ctf_stream_put(struct bt_ctf_stream *stream)
{
- if (!stream) {
- return;
- }
-
- bt_ctf_ref_put(&stream->ref_count, bt_ctf_stream_destroy);
+ bt_ctf_put(stream);
}
static
-void bt_ctf_stream_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_stream_destroy(struct bt_ref *ref)
{
struct bt_ctf_stream *stream;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- stream = container_of(ref, struct bt_ctf_stream, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ stream = container_of(base, struct bt_ctf_stream, base);
ctf_fini_pos(&stream->pos);
if (stream->pos.fd >= 0 && close(stream->pos.fd)) {
perror("close");
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/compiler.h>
#include <babeltrace/objects.h>
#define DEFAULT_METADATA_STRING_SIZE 4096
static
-void bt_ctf_trace_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_trace_destroy(struct bt_ref *ref);
static
int init_trace_packet_header(struct bt_ctf_trace *trace);
static
}
bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE);
- bt_ctf_ref_init(&trace->ref_count);
+ bt_ctf_base_init(trace, bt_ctf_trace_destroy);
trace->clocks = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_ctf_clock_put);
trace->streams = g_ptr_array_new_with_free_func(
return trace;
error_destroy:
- bt_ctf_trace_destroy(&trace->ref_count);
+ bt_ctf_trace_destroy(&trace->base.ref_count);
trace = NULL;
error:
return trace;
}
-void bt_ctf_trace_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_trace_destroy(struct bt_ref *ref)
{
struct bt_ctf_trace *trace;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- trace = container_of(ref, struct bt_ctf_trace, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ trace = container_of(base, struct bt_ctf_trace, base);
if (trace->environment) {
bt_ctf_attributes_destroy(trace->environment);
}
void bt_ctf_trace_get(struct bt_ctf_trace *trace)
{
- if (!trace) {
- return;
- }
-
- bt_ctf_ref_get(&trace->ref_count);
+ bt_ctf_get(trace);
}
void bt_ctf_trace_put(struct bt_ctf_trace *trace)
{
- if (!trace) {
- return;
- }
+ bt_ctf_put(trace);
- bt_ctf_ref_put(&trace->ref_count, bt_ctf_trace_destroy);
}
BT_HIDDEN
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
#include <babeltrace/ctf-ir/stream-internal.h>
+#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/compiler.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
static
-void bt_ctf_writer_destroy(struct bt_ctf_ref *ref);
+void bt_ctf_writer_destroy(struct bt_ref *ref);
static
int create_stream_file(struct bt_ctf_writer *writer,
struct bt_ctf_stream *stream);
goto error;
}
- bt_ctf_ref_init(&writer->ref_count);
+ bt_ctf_base_init(writer, bt_ctf_writer_destroy);
writer->path = g_string_new(path);
if (!writer->path) {
goto error_destroy;
error_destroy:
unlinkat(writer->trace_dir_fd, "metadata", 0);
- bt_ctf_writer_destroy(&writer->ref_count);
+ bt_ctf_writer_destroy(&writer->base.ref_count);
writer = NULL;
error:
return writer;
}
-void bt_ctf_writer_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_writer_destroy(struct bt_ref *ref)
{
struct bt_ctf_writer *writer;
+ struct bt_ctf_base *base;
if (!ref) {
return;
}
- writer = container_of(ref, struct bt_ctf_writer, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ writer = container_of(base, struct bt_ctf_writer, base);
bt_ctf_writer_flush_metadata(writer);
if (writer->path) {
g_string_free(writer->path, TRUE);
void bt_ctf_writer_get(struct bt_ctf_writer *writer)
{
- if (!writer) {
- return;
- }
-
- bt_ctf_ref_get(&writer->ref_count);
+ bt_ctf_get(writer);
}
void bt_ctf_writer_put(struct bt_ctf_writer *writer)
{
- if (!writer) {
- return;
- }
-
- bt_ctf_ref_put(&writer->ref_count, bt_ctf_writer_destroy);
+ bt_ctf_put(writer);
}
static
babeltrace/ctf-ir/event-fields.h \
babeltrace/ctf-ir/event-types.h \
babeltrace/ctf-ir/event.h \
+ babeltrace/ctf-ir/ref.h \
babeltrace/ctf-ir/stream.h \
babeltrace/ctf-ir/stream-class.h \
babeltrace/ctf-ir/trace.h \
babeltrace/iterator-internal.h \
babeltrace/trace-collection.h \
babeltrace/prio_heap.h \
+ babeltrace/ref-internal.h \
babeltrace/types.h \
babeltrace/ctf-ir/metadata.h \
babeltrace/ctf/events-internal.h \
babeltrace/ctf/types.h \
babeltrace/ctf/callbacks-internal.h \
babeltrace/ctf/ctf-index.h \
- babeltrace/ctf-writer/ref-internal.h \
babeltrace/ctf-writer/writer-internal.h \
babeltrace/ctf-ir/attributes-internal.h \
+ babeltrace/ctf-ir/common-internal.h \
babeltrace/ctf-ir/event-types-internal.h \
babeltrace/ctf-ir/event-fields-internal.h \
babeltrace/ctf-ir/event-internal.h \
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-ir/trace-internal.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <glib.h>
#include <babeltrace/compat/uuid.h>
struct bt_ctf_clock {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
GString *name;
GString *description;
uint64_t frequency;
* bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the
* refcount of the clock
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with clock objects.
+ *
* These functions ensure that the clock won't be destroyed when it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) has to be done to
--- /dev/null
+#ifndef BABELTRACE_CTF_IR_COMMON_INTERNAL_H
+#define BABELTRACE_CTF_IR_COMMON_INTERNAL_H
+
+/*
+ * Babeltrace - CTF IR: common data structures
+ *
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Philippe Proulx <pproulx@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/ref-internal.h>
+
+/*
+ * bt_ctf_trace must be the base class of _all_ CTF IR classes and is assumed
+ * to be the first member of all bt_ctf_* structures.
+ */
+struct bt_ctf_base {
+ struct bt_ref ref_count;
+};
+
+static inline
+void bt_ctf_base_init(void *obj, bt_ref_release_func_t release_func)
+{
+ struct bt_ctf_base *base = obj;
+
+ bt_ref_init(&base->ref_count, release_func);
+}
+
+#endif /* BABELTRACE_CTF_IR_COMMON_INTERNAL_H */
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/event-fields.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
#include <glib.h>
struct bt_ctf_field {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
struct bt_ctf_field_type *type;
int payload_set;
};
* bt_ctf_field_get and bt_ctf_field_put: increment and decrement the
* field's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with field objects.
+ *
* These functions ensure that the field won't be destroyed when it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
#include <babeltrace/ctf-ir/stream-class.h>
#include <babeltrace/ctf-ir/stream.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <glib.h>
#define BT_CTF_EVENT_CLASS_ATTR_ID_INDEX 0
#define BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX 1
struct bt_ctf_event_class {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
struct bt_object *attributes;
/*
* Weak reference; an event class does not have ownership of a
};
struct bt_ctf_event {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
struct bt_ctf_event_class *event_class;
/* Weak reference; an event does not have ownership of a stream */
struct bt_ctf_stream *stream;
*/
#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/writer.h>
#include <babeltrace/ctf-ir/trace-internal.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/ctf/events.h>
};
struct bt_ctf_field_type {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
struct bt_declaration *declaration;
type_freeze_func freeze;
type_serialize_func serialize;
* bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement
* the field type's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with field type objects.
+ *
* These functions ensure that the field type won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
* bt_ctf_event_class_get and bt_ctf_event_class_put: increment and decrement
* the event class' reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with event class objects.
+ *
* These functions ensure that the event class won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
* bt_ctf_event_get and bt_ctf_event_put: increment and decrement
* the event's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with event objects.
+ *
* These functions ensure that the event won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
--- /dev/null
+#ifndef BABELTRACE_CTF_IR_REF_H
+#define BABELTRACE_CTF_IR_REF_H
+
+/*
+ * BabelTrace - CTF IR: common reference counting
+ *
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Philippe Proulx <pproulx@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 <assert.h>
+#include <babeltrace/ref-internal.h>
+#include <babeltrace/ctf-ir/common-internal.h>
+
+/*
+ * BT_CTF_PUT: calls bt_ctf_put() with a variable, then sets this
+ * variable to NULL.
+ *
+ * A common action with CTF IR objects is to create or get one, do
+ * something with it, and then put it. To avoid putting it a second time
+ * later (if an error occurs, for example), the variable is often reset
+ * to NULL after putting the object it points to. Since this is so
+ * common, you can use the BT_CTF_PUT() macro, which does just that.
+ *
+ * It is safe to call this function with a NULL object.
+ *
+ * @param obj CTF IR object.
+ */
+#define BT_CTF_PUT(_obj) \
+ do { \
+ bt_ctf_put(_obj); \
+ (_obj) = NULL; \
+ } while (0)
+
+/*
+ * bt_ctf_get: increments the reference count of a CTF IR object.
+ *
+ * The same number of bt_ctf_get() and bt_ctf_put() (plus one extra
+ * bt_ctf_put() to release the initial reference done at creation) have
+ * to be done to destroy a CTF IR object.
+ *
+ * It is safe to call this function with a NULL object.
+ *
+ * @param obj CTF IR object.
+ */
+static inline
+void bt_ctf_get(void *obj)
+{
+ if (obj) {
+ struct bt_ctf_base *base = obj;
+
+ bt_ref_get(&base->ref_count);
+ }
+}
+
+/*
+ * bt_ctf_put: decrements the reference count of a CTF IR object.
+ *
+ * The same number of bt_ctf_get() and bt_ctf_put() (plus one extra
+ * bt_ctf_put() to release the initial reference done at creation) have
+ * to be done to destroy a CTF IR object.
+ *
+ * When the object's reference count is decremented to 0 by a call to
+ * bt_ctf_put(), the object is freed.
+ *
+ * It is safe to call this function with a NULL object.
+ *
+ * @param obj CTF IR object.
+ */
+static inline
+void bt_ctf_put(void *obj)
+{
+ if (obj) {
+ struct bt_ctf_base *base = obj;
+
+ bt_ref_put(&base->ref_count);
+ }
+}
+
+#endif /* BABELTRACE_CTF_IR_REF_H */
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
#include <glib.h>
struct bt_ctf_stream_class {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
GString *name;
struct bt_ctf_clock *clock;
GPtrArray *event_classes; /* Array of pointers to bt_ctf_event_class */
* bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and
* decrement the stream class' reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with stream class objects.
+ *
* These functions ensure that the stream class won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
*/
#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <glib.h>
struct bt_ctf_stream {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
/* Trace owning this stream. A stream does not own a trace. */
struct bt_ctf_trace *trace;
uint32_t id;
* bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the
* stream's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with stream objects.
+ *
* These functions ensure that the stream won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-ir/trace.h>
#include <babeltrace/ctf-ir/event-types.h>
#include <babeltrace/ctf-ir/event-fields.h>
+#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/objects.h>
#include <glib.h>
};
struct bt_ctf_trace {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
int frozen;
uuid_t uuid;
int byte_order; /* A value defined in Babeltrace's "endian.h" */
* bt_ctf_trace_get and bt_ctf_trace_put: increment and decrement the
* trace's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with trace objects.
+ *
* These functions ensure that the trace won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
+++ /dev/null
-#ifndef BABELTRACE_CTF_WRITER_REF_INTERNAL_H
-#define BABELTRACE_CTF_WRITER_REF_INTERNAL_H
-
-/*
- * BabelTrace - CTF Writer: Reference count
- *
- * 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 <assert.h>
-
-struct bt_ctf_ref {
- long refcount;
-};
-
-static inline
-void bt_ctf_ref_init(struct bt_ctf_ref *ref)
-{
- assert(ref);
- ref->refcount = 1;
-}
-
-static inline
-void bt_ctf_ref_get(struct bt_ctf_ref *ref)
-{
- assert(ref);
- ref->refcount++;
-}
-
-static inline
-void bt_ctf_ref_put(struct bt_ctf_ref *ref,
- void (*release)(struct bt_ctf_ref *))
-{
- assert(ref);
- assert(release);
- if ((--ref->refcount) == 0) {
- release(ref);
- }
-}
-
-#endif /* BABELTRACE_CTF_WRITER_REF_INTERNAL_H */
* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
#include <babeltrace/ctf-writer/writer.h>
#include <babeltrace/babeltrace-internal.h>
#include <glib.h>
#include <dirent.h>
#include <sys/types.h>
#include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/ctf-ir/common-internal.h>
struct bt_ctf_writer {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_base base;
int frozen; /* Protects attributes that can't be changed mid-trace */
struct bt_ctf_trace *trace;
GString *path;
* bt_ctf_writer_get and bt_ctf_writer_put: increment and decrement the
* writer's reference count.
*
+ * You may also use bt_ctf_get() and bt_ctf_put() with writer objects.
+ *
* These functions ensure that the writer won't be destroyed while it
* is in use. The same number of get and put (plus one extra put to
* release the initial reference done at creation) have to be done to
--- /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 <assert.h>
+
+struct bt_ref;
+
+typedef void (*bt_ref_release_func_t)(struct bt_ref *);
+
+struct bt_ref {
+ long refcount;
+ bt_ref_release_func_t release_func;
+};
+
+static inline
+void bt_ref_init(struct bt_ref *ref,
+ bt_ref_release_func_t release_func)
+{
+ assert(ref);
+ ref->refcount = 1;
+ ref->release_func = release_func;
+}
+
+static inline
+void bt_ref_get(struct bt_ref *ref)
+{
+ assert(ref);
+ ref->refcount++;
+}
+
+static inline
+void bt_ref_put(struct bt_ref *ref)
+{
+ assert(ref);
+ assert(ref->release_func);
+ if ((--ref->refcount) == 0) {
+ ref->release_func(ref);
+ }
+}
+
+#endif /* BABELTRACE_REF_INTERNAL_H */
#include <string.h>
#include <assert.h>
#include <string.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/ref-internal.h>
#include <babeltrace/compiler.h>
-#include <glib.h>
#include <babeltrace/objects.h>
+#include <glib.h>
#define BT_OBJECT_FROM_CONCRETE(_concrete) ((struct bt_object *) (_concrete))
#define BT_OBJECT_TO_BOOL(_base) ((struct bt_object_bool *) (_base))
struct bt_object {
enum bt_object_type type;
- struct bt_ctf_ref ref_count;
+ struct bt_ref ref_count;
bool is_frozen;
};
GHashTable *ght;
};
+static
+void bt_object_destroy(struct bt_ref *ref_count);
+
static
void bt_object_string_destroy(struct bt_object *object)
{
};
static
-void bt_object_destroy(struct bt_ctf_ref *ref_count)
+void bt_object_destroy(struct bt_ref *ref_count)
{
struct bt_object *object;
void bt_object_get(struct bt_object *object)
{
- if (!object) {
- goto skip;
+ if (object && !bt_object_is_null(object)) {
+ bt_ref_get(&object->ref_count);
}
- bt_ctf_ref_get(&object->ref_count);
-
-skip:
return;
}
void bt_object_put(struct bt_object *object)
{
- if (!object) {
- goto skip;
+ if (object && !bt_object_is_null(object)) {
+ bt_ref_put(&object->ref_count);
}
-
- bt_ctf_ref_put(&object->ref_count, bt_object_destroy);
-
-skip:
- return;
}
enum bt_object_status bt_object_freeze(struct bt_object *object)
base.type = type;
base.is_frozen = false;
- bt_ctf_ref_init(&base.ref_count);
+ bt_ref_init(&base.ref_count, bt_object_destroy);
return base;
}