X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Ftrace.c;h=d5786d337251dff7c0e2f660ee5a5e7edad89ad2;hb=de3dd40e6fcad56e227f5fc8a8290fbaa88b4e07;hp=b8f4f7258d0bc66463d03cff58b386b60d3fcfde;hpb=2bd7f864589729c1e9bb2824b13a62a687d7e9f7;p=babeltrace.git diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index b8f4f725..d5786d33 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include @@ -42,11 +44,11 @@ #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 -void bt_ctf_trace_freeze(struct bt_ctf_trace *trace); +int bt_ctf_trace_freeze(struct bt_ctf_trace *trace); static const unsigned int field_type_aliases_alignments[] = { @@ -83,7 +85,7 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) } 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( @@ -109,21 +111,23 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) 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); } @@ -156,11 +160,6 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, goto error; } - stream = bt_ctf_stream_create(stream_class, trace); - if (!stream) { - goto error; - } - for (i = 0; i < trace->stream_classes->len; i++) { if (trace->stream_classes->pdata[i] == stream_class) { stream_class_found = 1; @@ -174,6 +173,11 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, } } + stream = bt_ctf_stream_create(stream_class, trace); + if (!stream) { + goto error; + } + bt_ctf_stream_get(stream); g_ptr_array_add(trace->streams, stream); @@ -504,7 +508,8 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, bt_ctf_stream_class_freeze(stream_class); if (!trace->frozen) { - bt_ctf_trace_freeze(trace); + ret = bt_ctf_trace_freeze(trace); + goto end; } end: if (ret) { @@ -858,45 +863,47 @@ end: 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 struct bt_ctf_field_type *get_field_type(enum field_type_alias alias) { unsigned int alignment, size; - struct bt_ctf_field_type *field_type; + struct bt_ctf_field_type *field_type = NULL; if (alias >= NR_FIELD_TYPE_ALIAS) { - return NULL; + goto end; } alignment = field_type_aliases_alignments[alias]; size = field_type_aliases_sizes[alias]; field_type = bt_ctf_field_type_integer_create(size); bt_ctf_field_type_set_alignment(field_type, alignment); +end: return field_type; } static -void bt_ctf_trace_freeze(struct bt_ctf_trace *trace) +int bt_ctf_trace_freeze(struct bt_ctf_trace *trace) { - bt_ctf_trace_resolve_types(trace); + int ret = 0; + + ret = bt_ctf_trace_resolve_types(trace); + if (ret) { + goto end; + } + bt_ctf_attributes_freeze(trace->environment); trace->frozen = 1; +end: + return ret; } static