From d3814b5400bc383ee8645cd76017e2aa6fea5dfe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 19 Mar 2015 21:43:00 -0400 Subject: [PATCH] ir: add weak reference to parent trace to bt_ctf_stream_class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/stream-class.c | 22 ++++++++++++++++++ formats/ctf/ir/trace.c | 23 ++++++++++++++++--- .../babeltrace/ctf-ir/stream-class-internal.h | 7 ++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 9ef5ca79..22ea8a5d 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -666,6 +666,28 @@ end: return ret; } +BT_HIDDEN +int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class, + struct bt_ctf_trace *trace) +{ + int ret = 0; + + if (!stream_class) { + ret = -1; + goto end; + } + + if (stream_class->trace && trace) { + /* Already attached to a trace */ + ret = -1; + goto end; + } + + stream_class->trace = trace; +end: + return ret; +} + static void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) { diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index e7dcfdae..476d62c3 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -62,6 +62,13 @@ const unsigned int field_type_aliases_sizes[] = { [FIELD_TYPE_ALIAS_UINT64_T] = 64, }; +static +void put_stream_class(struct bt_ctf_stream_class *stream_class) +{ + (void) bt_ctf_stream_class_set_trace(stream_class, NULL); + bt_ctf_stream_class_put(stream_class); +} + struct bt_ctf_trace *bt_ctf_trace_create(void) { struct bt_ctf_trace *trace = NULL; @@ -74,11 +81,11 @@ 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); trace->clocks = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_clock_put); + (GDestroyNotify) bt_ctf_clock_put); trace->streams = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_stream_put); + (GDestroyNotify) bt_ctf_stream_put); trace->stream_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_stream_class_put); + (GDestroyNotify) put_stream_class); if (!trace->clocks || !trace->stream_classes || !trace->streams) { goto error_destroy; } @@ -403,6 +410,13 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, } } + /* Set weak reference to trace in stream class */ + ret = bt_ctf_stream_class_set_trace(stream_class, trace); + if (ret) { + /* Stream class already part of another trace */ + goto end; + } + bt_ctf_stream_class_get(stream_class); g_ptr_array_add(trace->stream_classes, stream_class); @@ -425,6 +439,9 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, bt_ctf_attributes_freeze(trace->environment); end: + if (ret) { + (void) bt_ctf_stream_class_set_trace(stream_class, NULL); + } return ret; } diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 8301fea0..3b368d1d 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,8 @@ struct bt_ctf_stream_class { uint32_t id; uint32_t next_event_id; uint32_t next_stream_id; + /* Weak reference; a stream class does not have ownership of a trace */ + struct bt_ctf_trace *trace; struct bt_ctf_field_type *packet_context_type; struct bt_ctf_field_type *event_header_type; struct bt_ctf_field_type *event_context_type; @@ -67,4 +70,8 @@ BT_HIDDEN int _bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id); +BT_HIDDEN +int bt_ctf_stream_class_set_trace(struct bt_ctf_stream_class *stream_class, + struct bt_ctf_trace *trace); + #endif /* BABELTRACE_CTF_IR_STREAM_CLASS_INTERNAL_H */ -- 2.34.1