From f4e8780dda876f6db1560ba0251e7e9a10d19ffc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 26 Jul 2024 21:07:41 +0000 Subject: [PATCH] sessiond: trace-ust.cpp: iterate on lfht using lfht_iteration_adapter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I5f87aebb6d8e4fc0ef6a4088faf0b7b1a84f37d0 Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/trace-ust.cpp | 99 ++++++++++------------------ 1 file changed, 35 insertions(+), 64 deletions(-) diff --git a/src/bin/lttng-sessiond/trace-ust.cpp b/src/bin/lttng-sessiond/trace-ust.cpp index 07e228d61..9a4e2b037 100644 --- a/src/bin/lttng-sessiond/trace-ust.cpp +++ b/src/bin/lttng-sessiond/trace-ust.cpp @@ -461,7 +461,7 @@ enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, try { local_ust_event = lttng::make_unique(); - } catch (const std::bad_alloc &ex) { + } catch (const std::bad_alloc& ex) { ERR_FMT("Failed to allocate ltt_ust_event"); ret = LTTNG_ERR_NOMEM; goto error; @@ -751,22 +751,18 @@ end: */ static void fini_id_tracker(struct ust_id_tracker *id_tracker) { - struct ust_id_tracker_node *tracker_node; - struct lttng_ht_iter iter; - if (!id_tracker->ht) { return; } - { - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (id_tracker->ht->ht, &iter.iter, tracker_node, node.node) { - const int ret = lttng_ht_del(id_tracker->ht, &iter); + for (auto *tracker_node : + lttng::urcu::lfht_iteration_adapter(*id_tracker->ht->ht)) { + const int ret = cds_lfht_del(id_tracker->ht->ht, &tracker_node->node.node); - LTTNG_ASSERT(!ret); - destroy_id_tracker_node(tracker_node); - } + LTTNG_ASSERT(!ret); + destroy_id_tracker_node(tracker_node); } lttng_ht_destroy(id_tracker->ht); @@ -1195,25 +1191,17 @@ static void destroy_context_rcu(struct rcu_head *head) */ static void destroy_contexts(struct lttng_ht *ht) { - int ret; - struct lttng_ht_node_ulong *node; - struct lttng_ht_iter iter; - struct ltt_ust_context *ctx; - LTTNG_ASSERT(ht); - { - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (ht->ht, &iter.iter, node, node) { - /* Remove from ordered list. */ - ctx = lttng::utils::container_of(node, <t_ust_context::node); - cds_list_del(&ctx->list); - /* Remove from channel's hash table. */ - ret = lttng_ht_del(ht, &iter); - if (!ret) { - call_rcu(&node->head, destroy_context_rcu); - } + for (auto *ctx : lttng::urcu::lfht_iteration_adapter(*ht->ht)) { + /* Remove from ordered list. */ + cds_list_del(&ctx->list); + /* Remove from channel's hash table. */ + const auto ret = cds_lfht_del(ht->ht, &ctx->node.node); + if (!ret) { + call_rcu(&ctx->node.head, destroy_context_rcu); } } @@ -1264,20 +1252,14 @@ static void destroy_event_rcu(struct rcu_head *head) */ static void destroy_events(struct lttng_ht *events) { - int ret; - struct lttng_ht_node_str *node; - struct lttng_ht_iter iter; - LTTNG_ASSERT(events); - { - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (events->ht, &iter.iter, node, node) { - ret = lttng_ht_del(events, &iter); - LTTNG_ASSERT(!ret); - call_rcu(&node->head, destroy_event_rcu); - } + for (auto *event : lttng::urcu::lfht_iteration_adapter(*events->ht)) { + const auto ret = cds_lfht_del(events->ht, &event->node.node); + LTTNG_ASSERT(!ret); + call_rcu(&event->node.head, destroy_event_rcu); } lttng_ht_destroy(events); @@ -1365,21 +1347,14 @@ end: */ static void destroy_channels(struct lttng_ht *channels) { - struct lttng_ht_node_str *node; - struct lttng_ht_iter iter; - LTTNG_ASSERT(channels); - { - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (channels->ht, &iter.iter, node, node) { - struct ltt_ust_channel *chan = - lttng::utils::container_of(node, <t_ust_channel::node); - - trace_ust_delete_channel(channels, chan); - trace_ust_destroy_channel(chan); - } + for (auto *chan : + lttng::urcu::lfht_iteration_adapter(*channels->ht)) { + trace_ust_delete_channel(channels, chan); + trace_ust_destroy_channel(chan); } lttng_ht_destroy(channels); @@ -1401,9 +1376,7 @@ static void destroy_domain_global(struct ltt_ust_domain_global *dom) */ void trace_ust_destroy_session(struct ltt_ust_session *session) { - struct agent *agt; struct buffer_reg_uid *reg, *sreg; - struct lttng_ht_iter iter; LTTNG_ASSERT(session); @@ -1412,15 +1385,13 @@ void trace_ust_destroy_session(struct ltt_ust_session *session) /* Cleaning up UST domain */ destroy_domain_global(&session->domain_global); - { - const lttng::urcu::read_lock_guard read_lock; - - cds_lfht_for_each_entry (session->agents->ht, &iter.iter, agt, node.node) { - const int ret = lttng_ht_del(session->agents, &iter); + for (auto *agt : + lttng::urcu::lfht_iteration_adapter( + *session->agents->ht)) { + const int ret = cds_lfht_del(session->agents->ht, &agt->node.node); - LTTNG_ASSERT(!ret); - agent_destroy(agt); - } + LTTNG_ASSERT(!ret); + agent_destroy(agt); } lttng_ht_destroy(session->agents); -- 2.39.5