From 1a25881946640f778a14e8f5491795193572d826 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 10 Nov 2021 13:59:59 -0500 Subject: [PATCH] src.ctf.lttng-live: use optional pattern for `ctf_stream_class_id` Instead of checking for an initial boundary value to signify if the value is initialized use a optional like anonymous struct with a `is_set` flag. Signed-off-by: Francis Deslauriers Change-Id: I3045ef884345bea58824fd2170d29e982d219b7a Reviewed-on: https://review.lttng.org/c/babeltrace/+/6699 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/ctf/lttng-live/data-stream.c | 5 ++++- src/plugins/ctf/lttng-live/lttng-live.c | 2 +- src/plugins/ctf/lttng-live/lttng-live.h | 5 ++++- src/plugins/ctf/lttng-live/viewer-connection.c | 14 ++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index d7fdf346..e8f00d7f 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -222,7 +222,10 @@ struct lttng_live_stream_iterator *lttng_live_stream_iterator_create( stream_iter->trace = trace; stream_iter->state = LTTNG_LIVE_STREAM_ACTIVE_NO_DATA; stream_iter->viewer_stream_id = stream_id; - stream_iter->ctf_stream_class_id = -1ULL; + + stream_iter->ctf_stream_class_id.is_set = false; + stream_iter->ctf_stream_class_id.value = UINT64_MAX; + stream_iter->last_inactivity_ts.is_set = false; stream_iter->last_inactivity_ts.value = 0; diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 65e07934..f091ae6e 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -671,7 +671,7 @@ enum lttng_live_iterator_status emit_inactivity_message( BT_COMP_LOGD("Emitting inactivity message for stream: ctf-stream-id=%" PRIu64 ", viewer-stream-id=%" PRIu64 ", timestamp=%" PRIu64, - stream_iter->ctf_stream_class_id, + stream_iter->ctf_stream_class_id.value, stream_iter->viewer_stream_id, timestamp); msg = bt_message_message_iterator_inactivity_create( diff --git a/src/plugins/ctf/lttng-live/lttng-live.h b/src/plugins/ctf/lttng-live/lttng-live.h index be235a7d..d0d5b153 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.h +++ b/src/plugins/ctf/lttng-live/lttng-live.h @@ -65,7 +65,10 @@ struct lttng_live_stream_iterator { uint64_t viewer_stream_id; - uint64_t ctf_stream_class_id; + struct { + bool is_set; + uint64_t value; + } ctf_stream_class_id; /* base offset in current index. */ uint64_t base_offset; diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index c4b29ed2..34bac35a 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -1539,11 +1539,12 @@ enum lttng_live_iterator_status lttng_live_get_next_index( index->ts_cycles.timestamp_end = be64toh(rp.timestamp_end); stream->current_inactivity_ts = index->ts_cycles.timestamp_end; ctf_stream_class_id = be64toh(rp.stream_id); - if (stream->ctf_stream_class_id != -1ULL) { - BT_ASSERT(stream->ctf_stream_class_id == + if (stream->ctf_stream_class_id.is_set) { + BT_ASSERT(stream->ctf_stream_class_id.value== ctf_stream_class_id); } else { - stream->ctf_stream_class_id = ctf_stream_class_id; + stream->ctf_stream_class_id.value = ctf_stream_class_id; + stream->ctf_stream_class_id.is_set = true; } lttng_live_stream_iterator_set_state(stream, LTTNG_LIVE_STREAM_QUIESCENT); status = LTTNG_LIVE_ITERATOR_STATUS_OK; @@ -1555,11 +1556,12 @@ enum lttng_live_iterator_status lttng_live_get_next_index( lttng_index_to_packet_index(&rp, index); ctf_stream_class_id = be64toh(rp.stream_id); - if (stream->ctf_stream_class_id != -1ULL) { - BT_ASSERT(stream->ctf_stream_class_id == + if (stream->ctf_stream_class_id.is_set) { + BT_ASSERT(stream->ctf_stream_class_id.value== ctf_stream_class_id); } else { - stream->ctf_stream_class_id = ctf_stream_class_id; + stream->ctf_stream_class_id.value = ctf_stream_class_id; + stream->ctf_stream_class_id.is_set = true; } lttng_live_stream_iterator_set_state(stream, LTTNG_LIVE_STREAM_ACTIVE_DATA); -- 2.34.1