Use compiler-agnostic defines to silence warning
[lttng-tools.git] / src / bin / lttng-sessiond / context.cpp
index b3b549187ecd57fcf5f7d989de230bc00ae6abbf..9a098841cb3aaa2e1ccf98fc69a55b87cc067d2b 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <common/error.hpp>
 #include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/urcu.hpp>
 
 #include <stdio.h>
 #include <unistd.h>
@@ -29,7 +30,6 @@ static int add_kctx_all_channels(struct ltt_kernel_session *ksession,
                                 struct ltt_kernel_context *kctx)
 {
        int ret;
-       struct ltt_kernel_channel *kchan;
 
        LTTNG_ASSERT(ksession);
        LTTNG_ASSERT(kctx);
@@ -37,7 +37,9 @@ static int add_kctx_all_channels(struct ltt_kernel_session *ksession,
        DBG("Adding kernel context to all channels");
 
        /* Go over all channels */
-       cds_list_for_each_entry (kchan, &ksession->channel_list.head, list) {
+       for (auto kchan :
+            lttng::urcu::list_iteration_adapter<ltt_kernel_channel, &ltt_kernel_channel::list>(
+                    ksession->channel_list.head)) {
                struct ltt_kernel_context *kctx_copy;
 
                kctx_copy = trace_kernel_copy_context(kctx);
@@ -98,24 +100,26 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess,
                               const struct lttng_event_context *ctx)
 {
        int ret;
-       struct ltt_ust_context *uctx = nullptr;
+       struct ltt_ust_context *new_uctx = nullptr;
 
        LTTNG_ASSERT(usess);
        LTTNG_ASSERT(uchan);
        LTTNG_ASSERT(ctx);
 
        /* Check if context is duplicate */
-       cds_list_for_each_entry (uctx, &uchan->ctx_list, list) {
-               if (trace_ust_match_context(uctx, ctx)) {
+       for (auto uctx_it :
+            lttng::urcu::list_iteration_adapter<ltt_ust_context, &ltt_ust_context::list>(
+                    uchan->ctx_list)) {
+               if (trace_ust_match_context(uctx_it, ctx)) {
                        ret = LTTNG_ERR_UST_CONTEXT_EXIST;
                        goto duplicate;
                }
        }
-       uctx = nullptr;
 
        switch (domain) {
        case LTTNG_DOMAIN_JUL:
        case LTTNG_DOMAIN_LOG4J:
+       case LTTNG_DOMAIN_LOG4J2:
        {
                struct agent *agt;
 
@@ -151,31 +155,31 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess,
        }
 
        /* Create ltt UST context */
-       uctx = trace_ust_create_context(ctx);
-       if (uctx == nullptr) {
+       new_uctx = trace_ust_create_context(ctx);
+       if (new_uctx == nullptr) {
                ret = LTTNG_ERR_UST_CONTEXT_INVAL;
                goto error;
        }
 
        /* Add ltt UST context node to ltt UST channel */
-       lttng_ht_add_ulong(uchan->ctx, &uctx->node);
-       cds_list_add_tail(&uctx->list, &uchan->ctx_list);
+       lttng_ht_add_ulong(uchan->ctx, &new_uctx->node);
+       cds_list_add_tail(&new_uctx->list, &uchan->ctx_list);
 
        if (!usess->active) {
                goto end;
        }
 
-       ret = ust_app_add_ctx_channel_glb(usess, uchan, uctx);
+       ret = ust_app_add_ctx_channel_glb(usess, uchan, new_uctx);
        if (ret < 0) {
                goto error;
        }
 end:
-       DBG("Context UST %d added to channel %s", uctx->ctx.ctx, uchan->name);
+       DBG("Context UST %d added to channel %s", new_uctx->ctx.ctx, uchan->name);
 
        return 0;
 
 error:
-       free(uctx);
+       free(new_uctx);
 duplicate:
        return ret;
 }
@@ -366,15 +370,14 @@ int context_ust_add(struct ltt_ust_session *usess,
                    const char *channel_name)
 {
        int ret = LTTNG_OK;
-       struct lttng_ht_iter iter;
        struct lttng_ht *chan_ht;
-       struct ltt_ust_channel *uchan = nullptr;
+       ltt_ust_channel *uchan = nullptr;
 
        LTTNG_ASSERT(usess);
        LTTNG_ASSERT(ctx);
        LTTNG_ASSERT(channel_name);
 
-       rcu_read_lock();
+       const lttng::urcu::read_lock_guard read_lock;
 
        chan_ht = usess->domain_global.channels;
 
@@ -391,16 +394,17 @@ int context_ust_add(struct ltt_ust_session *usess,
                /* Add ctx to channel */
                ret = add_uctx_to_channel(usess, domain, uchan, ctx);
        } else {
-               rcu_read_lock();
                /* Add ctx all events, all channels */
-               cds_lfht_for_each_entry (chan_ht->ht, &iter.iter, uchan, node.node) {
-                       ret = add_uctx_to_channel(usess, domain, uchan, ctx);
+               for (auto *iterated_uchan :
+                    lttng::urcu::lfht_iteration_adapter<ltt_ust_channel,
+                                                        decltype(ltt_ust_channel::node),
+                                                        &ltt_ust_channel::node>(*chan_ht->ht)) {
+                       ret = add_uctx_to_channel(usess, domain, iterated_uchan, ctx);
                        if (ret) {
-                               ERR("Failed to add context to channel %s", uchan->name);
+                               ERR("Failed to add context to channel %s", iterated_uchan->name);
                                continue;
                        }
                }
-               rcu_read_unlock();
        }
 
        switch (ret) {
@@ -426,6 +430,5 @@ int context_ust_add(struct ltt_ust_session *usess,
        }
 
 error:
-       rcu_read_unlock();
        return ret;
 }
This page took 0.026025 seconds and 4 git commands to generate.