From: Jérémie Galarneau Date: Mon, 22 Jul 2024 19:04:48 +0000 (+0000) Subject: relayd: use lfht_iteration_adapter to iterate on stream indices X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7d9e46e28d465621af7f838f1101561e31780a36;p=lttng-tools.git relayd: use lfht_iteration_adapter to iterate on stream indices offsetof conditionally support for non-POD types and is used by the cds_lfht_for_each_[...] macros. Replace them with lfht_iteration_adapter which also provides ranged-for semantics. Change-Id: Id1460004322e1e778a1affd41c82527a05190f59 Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/index.cpp b/src/bin/lttng-relayd/index.cpp index 42d4bc311..a90798254 100644 --- a/src/bin/lttng-relayd/index.cpp +++ b/src/bin/lttng-relayd/index.cpp @@ -302,12 +302,10 @@ skip: */ void relay_index_close_all(struct relay_stream *stream) { - struct lttng_ht_iter iter; - struct relay_index *index; - - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (stream->indexes_ht->ht, &iter.iter, index, index_n.node) { + for (auto *index : + lttng::urcu::lfht_iteration_adapter(*stream->indexes_ht->ht)) { /* Put self-ref from index. */ relay_index_put(index); } @@ -315,12 +313,10 @@ void relay_index_close_all(struct relay_stream *stream) void relay_index_close_partial_fd(struct relay_stream *stream) { - struct lttng_ht_iter iter; - struct relay_index *index; - - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (stream->indexes_ht->ht, &iter.iter, index, index_n.node) { + for (auto *index : + lttng::urcu::lfht_iteration_adapter(*stream->indexes_ht->ht)) { if (!index->index_file) { continue; } @@ -335,13 +331,12 @@ void relay_index_close_partial_fd(struct relay_stream *stream) uint64_t relay_index_find_last(struct relay_stream *stream) { - struct lttng_ht_iter iter; - struct relay_index *index; uint64_t net_seq_num = -1ULL; - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (stream->indexes_ht->ht, &iter.iter, index, index_n.node) { + for (auto *index : + lttng::urcu::lfht_iteration_adapter(*stream->indexes_ht->ht)) { if (net_seq_num == -1ULL || index->index_n.key > net_seq_num) { net_seq_num = index->index_n.key; } @@ -386,21 +381,18 @@ end: */ int relay_index_switch_all_files(struct relay_stream *stream) { - struct lttng_ht_iter iter; - struct relay_index *index; - int ret = 0; - - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (stream->indexes_ht->ht, &iter.iter, index, index_n.node) { - ret = relay_index_switch_file( + for (auto *index : + lttng::urcu::lfht_iteration_adapter(*stream->indexes_ht->ht)) { + const auto ret = relay_index_switch_file( index, stream->index_file, stream->pos_after_last_complete_data_index); if (ret) { return ret; } } - return ret; + return 0; } /*