From 7d632b96cb0c572a64e34ab3bb66bddaf9eef2d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 25 Oct 2019 17:43:47 -0400 Subject: [PATCH] source.ctf.lttng-live: clean-up: don't restart session iteration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/ctf/lttng-live/lttng-live.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) 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++; } -- 2.34.1