common: replace container_of with a C++ safe implementation
[lttng-tools.git] / src / bin / lttng-sessiond / snapshot.cpp
index 03472201acfd3c68a4cdad1937b6b69095248801..e0ffe69c0b1a5303cebfe908ab99cee7eb2220d1 100644 (file)
 #include <string.h>
 #include <urcu/uatomic.h>
 
-#include <common/defaults.h>
+#include <common/defaults.hpp>
 
-#include "snapshot.h"
-#include "utils.h"
+#include "snapshot.hpp"
+#include "utils.hpp"
 
 /*
  * Return the atomically incremented value of next_output_id.
@@ -165,7 +165,7 @@ error:
 
 struct snapshot_output *snapshot_output_alloc(void)
 {
-       return (snapshot_output *) zmalloc(sizeof(struct snapshot_output));
+       return zmalloc<snapshot_output>();
 }
 
 /*
@@ -241,6 +241,7 @@ struct snapshot_output *snapshot_find_output_by_name(const char *name,
 
        LTTNG_ASSERT(snapshot);
        LTTNG_ASSERT(name);
+       ASSERT_RCU_READ_LOCKED();
 
        cds_lfht_for_each_entry(snapshot->output_ht->ht, &iter.iter, output,
                node.node) {
@@ -267,6 +268,7 @@ struct snapshot_output *snapshot_find_output_by_id(uint32_t id,
        struct snapshot_output *output = NULL;
 
        LTTNG_ASSERT(snapshot);
+       ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(snapshot->output_ht, (void *)((unsigned long) id), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
@@ -274,7 +276,7 @@ struct snapshot_output *snapshot_find_output_by_id(uint32_t id,
                DBG3("Snapshot output not found with id %" PRId32, id);
                goto error;
        }
-       output = caa_container_of(node, struct snapshot_output, node);
+       output = lttng::utils::container_of(node, &snapshot_output::node);
 
 error:
        return output;
@@ -325,5 +327,5 @@ void snapshot_destroy(struct snapshot *obj)
                snapshot_output_destroy(output);
        }
        rcu_read_unlock();
-       ht_cleanup_push(obj->output_ht);
+       lttng_ht_destroy(obj->output_ht);
 }
This page took 0.024028 seconds and 4 git commands to generate.