Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / snapshot.cpp
index dda699fc4bcf5ea6b6b8bf4c2d546ed336c5f7d9..e7a0033541a5d07d5cdafd77d5f4306e462e2662 100644 (file)
@@ -10,6 +10,7 @@
 #include "utils.hpp"
 
 #include <common/defaults.hpp>
+#include <common/urcu.hpp>
 
 #include <inttypes.h>
 #include <string.h>
@@ -157,7 +158,7 @@ int snapshot_output_init(const struct ltt_session *session,
                         struct snapshot *snapshot)
 {
        int ret = 0, nb_uri;
-       struct lttng_uri *uris = NULL;
+       struct lttng_uri *uris = nullptr;
 
        /* Create an array of URIs from URLs. */
        nb_uri = uri_parse_str_urls(ctrl_url, data_url, &uris);
@@ -173,7 +174,7 @@ error:
        return ret;
 }
 
-struct snapshot_output *snapshot_output_alloc(void)
+struct snapshot_output *snapshot_output_alloc()
 {
        return zmalloc<snapshot_output>();
 }
@@ -191,9 +192,8 @@ void snapshot_delete_output(struct snapshot *snapshot, struct snapshot_output *o
        LTTNG_ASSERT(output);
 
        iter.iter.node = &output->node.node;
-       rcu_read_lock();
+       lttng::urcu::read_lock_guard read_lock;
        ret = lttng_ht_del(snapshot->output_ht, &iter);
-       rcu_read_unlock();
        LTTNG_ASSERT(!ret);
        /*
         * This is safe because the ownership of a snapshot object is in a session
@@ -211,9 +211,8 @@ void snapshot_add_output(struct snapshot *snapshot, struct snapshot_output *outp
        LTTNG_ASSERT(snapshot->output_ht);
        LTTNG_ASSERT(output);
 
-       rcu_read_lock();
+       lttng::urcu::read_lock_guard read_lock;
        lttng_ht_add_unique_ulong(snapshot->output_ht, &output->node);
-       rcu_read_unlock();
        /*
         * This is safe because the ownership of a snapshot object is in a session
         * for which the session lock need to be acquired to read and modify it.
@@ -244,7 +243,7 @@ void snapshot_output_destroy(struct snapshot_output *obj)
 struct snapshot_output *snapshot_find_output_by_name(const char *name, struct snapshot *snapshot)
 {
        struct lttng_ht_iter iter;
-       struct snapshot_output *output = NULL;
+       struct snapshot_output *output = nullptr;
 
        LTTNG_ASSERT(snapshot);
        LTTNG_ASSERT(name);
@@ -257,7 +256,7 @@ struct snapshot_output *snapshot_find_output_by_name(const char *name, struct sn
        }
 
        /* Not found */
-       return NULL;
+       return nullptr;
 }
 
 /*
@@ -270,7 +269,7 @@ struct snapshot_output *snapshot_find_output_by_id(uint32_t id, struct snapshot
 {
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
-       struct snapshot_output *output = NULL;
+       struct snapshot_output *output = nullptr;
 
        LTTNG_ASSERT(snapshot);
        ASSERT_RCU_READ_LOCKED();
@@ -325,11 +324,14 @@ void snapshot_destroy(struct snapshot *obj)
                return;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (obj->output_ht->ht, &iter.iter, output, node.node) {
-               snapshot_delete_output(obj, output);
-               snapshot_output_destroy(output);
+       {
+               lttng::urcu::read_lock_guard read_lock;
+
+               cds_lfht_for_each_entry (obj->output_ht->ht, &iter.iter, output, node.node) {
+                       snapshot_delete_output(obj, output);
+                       snapshot_output_destroy(output);
+               }
        }
-       rcu_read_unlock();
+
        lttng_ht_destroy(obj->output_ht);
 }
This page took 0.026388 seconds and 4 git commands to generate.