From 0b68f2bcc2ee524fd201516ef0c9bec45e6529dc Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 7 Dec 2023 04:26:25 +0000 Subject: [PATCH] src.ctf.lttng-live: make lttng_live_stream_iterator::stream a bt2::Stream::Shared Change-Id: Ia38f2feba1040749df692574e67861c81a73e8df Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8454 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12369 Tested-by: jenkins --- src/plugins/ctf/lttng-live/data-stream.cpp | 20 +++++++++----------- src/plugins/ctf/lttng-live/lttng-live.cpp | 10 +++++----- src/plugins/ctf/lttng-live/lttng-live.hpp | 3 +-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/plugins/ctf/lttng-live/data-stream.cpp b/src/plugins/ctf/lttng-live/data-stream.cpp index cf49b7e3..8a68650b 100644 --- a/src/plugins/ctf/lttng-live/data-stream.cpp +++ b/src/plugins/ctf/lttng-live/data-stream.cpp @@ -71,6 +71,8 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t str "Creating stream {} (ID: {}) out of stream class {}", lttng_live_stream->name->str, stream_id, stream_class_id); + bt_stream *stream; + if (stream_id < 0) { /* * No stream instance ID in the stream. It's possible @@ -78,27 +80,27 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t str * LTTng. In these cases, use the viewer_stream_id that * is unique for a live viewer session. */ - lttng_live_stream->stream = + stream = bt_stream_create_with_id(stream_class, lttng_live_stream->trace->trace->libObjPtr(), lttng_live_stream->viewer_stream_id); } else { - lttng_live_stream->stream = bt_stream_create_with_id( + stream = bt_stream_create_with_id( stream_class, lttng_live_stream->trace->trace->libObjPtr(), (uint64_t) stream_id); } - if (!lttng_live_stream->stream) { + if (!stream) { BT_CPPLOGE_APPEND_CAUSE_SPEC( lttng_live_stream->logger, "Cannot create stream {} (stream class ID {}, stream ID {})", lttng_live_stream->name->str, stream_class_id, stream_id); - goto end; + return nullptr; } - bt_stream_set_name(lttng_live_stream->stream, lttng_live_stream->name->str); + lttng_live_stream->stream = bt2::Stream::Shared::createWithoutRef(stream); + lttng_live_stream->stream->name(lttng_live_stream->name->str); } -end: - return lttng_live_stream->stream; + return lttng_live_stream->stream->libObjPtr(); } static struct ctf_msg_iter_medium_ops medops = { @@ -241,10 +243,6 @@ void lttng_live_stream_iterator_destroy(struct lttng_live_stream_iterator *strea return; } - if (stream_iter->stream) { - BT_STREAM_PUT_REF_AND_RESET(stream_iter->stream); - } - if (stream_iter->msg_iter) { ctf_msg_iter_destroy(stream_iter->msg_iter); } diff --git a/src/plugins/ctf/lttng-live/lttng-live.cpp b/src/plugins/ctf/lttng-live/lttng-live.cpp index 4d4dd162..ae7e45b1 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.cpp +++ b/src/plugins/ctf/lttng-live/lttng-live.cpp @@ -1069,7 +1069,7 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, goto end; } - stream_class = bt_stream_borrow_class_const(stream_iter->stream); + stream_class = bt_stream_borrow_class_const(stream_iter->stream->libObjPtr()); clock_class = bt_stream_class_borrow_default_clock_class_const(stream_class); ts_ns_status = bt_clock_class_cycles_to_ns_from_origin( @@ -1105,13 +1105,13 @@ handle_late_message(struct lttng_live_msg_iter *lttng_live_msg_iter, switch (bt_message_get_type(late_msg)) { case BT_MESSAGE_TYPE_DISCARDED_EVENTS: adjust_status = adjust_discarded_events_message( - lttng_live_msg_iter->self_msg_iter, stream_iter->stream, late_msg, &adjusted_message, - stream_iter->last_inactivity_ts.value); + lttng_live_msg_iter->self_msg_iter, stream_iter->stream->libObjPtr(), late_msg, + &adjusted_message, stream_iter->last_inactivity_ts.value); break; case BT_MESSAGE_TYPE_DISCARDED_PACKETS: adjust_status = adjust_discarded_packets_message( - lttng_live_msg_iter->self_msg_iter, stream_iter->stream, late_msg, &adjusted_message, - stream_iter->last_inactivity_ts.value); + lttng_live_msg_iter->self_msg_iter, stream_iter->stream->libObjPtr(), late_msg, + &adjusted_message, stream_iter->last_inactivity_ts.value); break; default: bt_common_abort(); diff --git a/src/plugins/ctf/lttng-live/lttng-live.hpp b/src/plugins/ctf/lttng-live/lttng-live.hpp index a8ec55fc..2ed64481 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.hpp +++ b/src/plugins/ctf/lttng-live/lttng-live.hpp @@ -74,8 +74,7 @@ struct lttng_live_stream_iterator bt2c::Logger logger; - /* Owned by this. */ - bt_stream *stream = nullptr; + bt2::Stream::Shared stream; /* Weak reference. */ struct lttng_live_trace *trace = nullptr; -- 2.34.1