common: trace-chunk.cpp: iterate on lfht using lfht_iteration_adapter
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 26 Jul 2024 21:44:20 +0000 (21:44 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 30 Jul 2024 01:26:51 +0000 (01:26 +0000)
Change-Id: Ia05a6b974a9bafac993de76a781a22be487e94cd
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/trace-chunk.cpp

index 591768b92321ee40b371389a8dca589883fa8ead..9c30ef5b3790a16b5267b82e59793ea9e504b222 100644 (file)
@@ -2103,45 +2103,42 @@ lttng_trace_chunk_registry_find_anonymous_chunk(const struct lttng_trace_chunk_r
 unsigned int
 lttng_trace_chunk_registry_put_each_chunk(const struct lttng_trace_chunk_registry *registry)
 {
-       struct cds_lfht_iter iter;
-       struct lttng_trace_chunk_registry_element *chunk_element;
        unsigned int trace_chunks_left = 0;
 
        DBG("Releasing trace chunk registry to all trace chunks");
 
-       {
-               const lttng::urcu::read_lock_guard read_lock;
-
-               cds_lfht_for_each_entry (
-                       registry->ht, &iter, chunk_element, trace_chunk_registry_ht_node) {
-                       const char *chunk_id_str = "none";
-                       char chunk_id_buf[MAX_INT_DEC_LEN(uint64_t)];
-
-                       pthread_mutex_lock(&chunk_element->chunk.lock);
-                       if (chunk_element->chunk.id.is_set) {
-                               int fmt_ret;
-
-                               fmt_ret = snprintf(chunk_id_buf,
-                                                  sizeof(chunk_id_buf),
-                                                  "%" PRIu64,
-                                                  chunk_element->chunk.id.value);
-                               if (fmt_ret < 0 || fmt_ret >= sizeof(chunk_id_buf)) {
-                                       chunk_id_str = "formatting error";
-                               } else {
-                                       chunk_id_str = chunk_id_buf;
-                               }
+       for (auto *chunk_element : lttng::urcu::lfht_iteration_adapter<
+                    lttng_trace_chunk_registry_element,
+                    decltype(lttng_trace_chunk_registry_element::trace_chunk_registry_ht_node),
+                    &lttng_trace_chunk_registry_element::trace_chunk_registry_ht_node>(
+                    *registry->ht)) {
+               const char *chunk_id_str = "none";
+               char chunk_id_buf[MAX_INT_DEC_LEN(uint64_t)];
+
+               pthread_mutex_lock(&chunk_element->chunk.lock);
+               if (chunk_element->chunk.id.is_set) {
+                       int fmt_ret;
+
+                       fmt_ret = snprintf(chunk_id_buf,
+                                          sizeof(chunk_id_buf),
+                                          "%" PRIu64,
+                                          chunk_element->chunk.id.value);
+                       if (fmt_ret < 0 || fmt_ret >= sizeof(chunk_id_buf)) {
+                               chunk_id_str = "formatting error";
+                       } else {
+                               chunk_id_str = chunk_id_buf;
                        }
-
-                       DBG("Releasing reference to trace chunk: session_id = %" PRIu64
-                           "chunk_id = %s, name = \"%s\", status = %s",
-                           chunk_element->session_id,
-                           chunk_id_str,
-                           chunk_element->chunk.name ?: "none",
-                           chunk_element->chunk.close_command.is_set ? "open" : "closed");
-                       pthread_mutex_unlock(&chunk_element->chunk.lock);
-                       lttng_trace_chunk_put(&chunk_element->chunk);
-                       trace_chunks_left++;
                }
+
+               DBG("Releasing reference to trace chunk: session_id = %" PRIu64
+                   "chunk_id = %s, name = \"%s\", status = %s",
+                   chunk_element->session_id,
+                   chunk_id_str,
+                   chunk_element->chunk.name ?: "none",
+                   chunk_element->chunk.close_command.is_set ? "open" : "closed");
+               pthread_mutex_unlock(&chunk_element->chunk.lock);
+               lttng_trace_chunk_put(&chunk_element->chunk);
+               trace_chunks_left++;
        }
 
        DBG("Released reference to %u trace chunks in %s()", trace_chunks_left, __FUNCTION__);
This page took 0.027033 seconds and 4 git commands to generate.