Use compiler-agnostic defines to silence warning
[lttng-tools.git] / src / bin / lttng-sessiond / manage-kernel.cpp
index 49730f497654fe1af8d09be8f6920fa41bce1620..ddd935f272741e2de34b1fad3ecc8a1dec5dfbda 100644 (file)
 #include "thread.hpp"
 #include "utils.hpp"
 
+#include <common/make-unique-wrapper.hpp>
 #include <common/pipe.hpp>
+#include <common/pthread-lock.hpp>
+#include <common/urcu.hpp>
 #include <common/utils.hpp>
 
+#include <fcntl.h>
+
 namespace {
 struct thread_notifiers {
        struct lttng_pipe *quit_pipe;
@@ -32,17 +37,18 @@ struct thread_notifiers {
 static int update_kernel_poll(struct lttng_poll_event *events)
 {
        int ret;
-       struct ltt_kernel_channel *channel;
-       struct ltt_session *session;
-       const struct ltt_session_list *session_list = session_get_list();
 
        DBG("Updating kernel poll set");
 
-       session_lock_list();
-       cds_list_for_each_entry (session, &session_list->head, list) {
+       const auto list_lock = lttng::sessiond::lock_session_list();
+       const struct ltt_session_list *session_list = session_get_list();
+
+       for (auto *session : lttng::urcu::list_iteration_adapter<ltt_session, &ltt_session::list>(
+                    session_list->head)) {
                if (!session_get(session)) {
                        continue;
                }
+
                session_lock(session);
                if (session->kernel_session == nullptr) {
                        session_unlock(session);
@@ -50,27 +56,25 @@ static int update_kernel_poll(struct lttng_poll_event *events)
                        continue;
                }
 
-               cds_list_for_each_entry (
-                       channel, &session->kernel_session->channel_list.head, list) {
+               for (auto *channel : lttng::urcu::list_iteration_adapter<ltt_kernel_channel,
+                                                                        &ltt_kernel_channel::list>(
+                            session->kernel_session->channel_list.head)) {
                        /* Add channel fd to the kernel poll set */
                        ret = lttng_poll_add(events, channel->fd, LPOLLIN | LPOLLRDNORM);
                        if (ret < 0) {
                                session_unlock(session);
                                session_put(session);
-                               goto error;
+                               return -1;
                        }
+
                        DBG("Channel fd %d added to kernel set", channel->fd);
                }
+
                session_unlock(session);
                session_put(session);
        }
-       session_unlock_list();
 
        return 0;
-
-error:
-       session_unlock_list();
-       return -1;
 }
 
 /*
@@ -82,37 +86,39 @@ error:
 static int update_kernel_stream(int fd)
 {
        int ret = 0;
-       struct ltt_session *session;
-       struct ltt_kernel_session *ksess;
-       struct ltt_kernel_channel *channel;
-       const struct ltt_session_list *session_list = session_get_list();
 
        DBG("Updating kernel streams for channel fd %d", fd);
 
-       session_lock_list();
-       cds_list_for_each_entry (session, &session_list->head, list) {
-               if (!session_get(session)) {
-                       continue;
-               }
-               session_lock(session);
+       const auto list_lock = lttng::sessiond::lock_session_list();
+       const struct ltt_session_list *session_list = session_get_list();
+
+       for (auto *raw_session_ptr :
+            lttng::urcu::list_iteration_adapter<ltt_session, &ltt_session::list>(
+                    session_list->head)) {
+               ltt_kernel_session *ksess;
+
+               const auto session = [raw_session_ptr]() {
+                       session_get(raw_session_ptr);
+                       raw_session_ptr->lock();
+                       return ltt_session::make_locked_ref(*raw_session_ptr);
+               }();
+
                if (session->kernel_session == nullptr) {
-                       session_unlock(session);
-                       session_put(session);
                        continue;
                }
-               ksess = session->kernel_session;
 
-               cds_list_for_each_entry (channel, &ksess->channel_list.head, list) {
-                       struct lttng_ht_iter iter;
-                       struct consumer_socket *socket;
+               ksess = session->kernel_session;
 
+               for (auto *channel : lttng::urcu::list_iteration_adapter<ltt_kernel_channel,
+                                                                        &ltt_kernel_channel::list>(
+                            ksess->channel_list.head)) {
                        if (channel->fd != fd) {
                                continue;
                        }
                        DBG("Channel found, updating kernel streams");
                        ret = kernel_open_channel_stream(channel);
                        if (ret < 0) {
-                               goto error;
+                               return ret;
                        }
                        /* Update the stream global counter */
                        ksess->stream_count_global += ret;
@@ -123,34 +129,25 @@ static int update_kernel_stream(int fd)
                         * our updated stream fds.
                         */
                        if (ksess->consumer_fds_sent != 1 || ksess->consumer == nullptr) {
-                               ret = -1;
-                               goto error;
+                               return -1;
                        }
 
-                       rcu_read_lock();
-                       cds_lfht_for_each_entry (
-                               ksess->consumer->socks->ht, &iter.iter, socket, node.node) {
-                               pthread_mutex_lock(socket->lock);
+                       for (auto *socket :
+                            lttng::urcu::lfht_iteration_adapter<consumer_socket,
+                                                                decltype(consumer_socket::node),
+                                                                &consumer_socket::node>(
+                                    *ksess->consumer->socks->ht)) {
+                               const lttng::pthread::lock_guard socket_lock(*socket->lock);
+
                                ret = kernel_consumer_send_channel_streams(
                                        socket, channel, ksess, session->output_traces ? 1 : 0);
-                               pthread_mutex_unlock(socket->lock);
                                if (ret < 0) {
-                                       rcu_read_unlock();
-                                       goto error;
+                                       return ret;
                                }
                        }
-                       rcu_read_unlock();
                }
-               session_unlock(session);
-               session_put(session);
        }
-       session_unlock_list();
-       return ret;
 
-error:
-       session_unlock(session);
-       session_put(session);
-       session_unlock_list();
        return ret;
 }
 
This page took 0.026481 seconds and 4 git commands to generate.