From: Jérémie Galarneau Date: Fri, 25 Oct 2019 21:43:47 +0000 (-0400) Subject: source.ctf.lttng-live: clean-up: don't restart session iteration X-Git-Tag: v2.0.0-rc2~21 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=961b4173af535c7ffc697520ca754418b859e265 source.ctf.lttng-live: clean-up: don't restart session iteration Don't restart the iteration on a session array when a session has to be removed. The contents of the array's current position are replaced by the contents of the last position in the array. Thus, we can continue the iteration from the current index. Signed-off-by: Jérémie Galarneau Change-Id: If058fe4b10c9c422b9f54edd63900b6804bbe8e2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2264 Reviewed-by: Simon Marchi --- diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index 7da40dc2..1ea60733 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -1281,16 +1281,6 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next( BT_ASSERT_DBG(lttng_live_msg_iter->sessions); session_idx = 0; - /* - * Use a while loop instead of a for loop so we can restart the - * iteration if we remove an element. We can safely call - * next_stream_iterator_for_session() multiple times on the - * same session as we only fetch a new message if there is no - * current next message for each live stream iterator. - * If all live stream iterator of that session already have a - * current next message, the function will simply exit return - * the same candidate live stream iterator every time. - */ while (session_idx < lttng_live_msg_iter->sessions->len) { struct lttng_live_session *session = g_ptr_array_index(lttng_live_msg_iter->sessions, @@ -1308,14 +1298,15 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next( if (stream_iter_status == LTTNG_LIVE_ITERATOR_STATUS_END) { if (session->closed && session->traces->len == 0) { /* - * Remove the session from the list and restart the - * iteration at the beginning of the array since the - * removal shuffle the elements of the array. + * Remove the session from the list. + * session_idx is not modified since + * g_ptr_array_remove_index_fast + * replaces the the removed element with + * the array's last element. */ g_ptr_array_remove_index_fast( lttng_live_msg_iter->sessions, session_idx); - session_idx = 0; } else { session_idx++; }