hashtable: replace non-const iterator node accessors by a const version
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Jun 2024 19:00:17 +0000 (19:00 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 5 Jul 2024 16:48:58 +0000 (12:48 -0400)
The various lttng_ht_iter_get_node_* functions are not const-correct which makes
their use difficult in some places. This is mostly due to the fact that
cds_lfht_iter_get_node (from liburcu) is, itself, not const-correct.

These functions are replaced by a single templated function that is
const-correct by virtue of inlining the trivial iterator node accessor of
liburcu.

Change-Id: I4df87abedb1ec6b14eb52ce4c212a10805898954
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 files changed:
src/bin/lttng-relayd/connection.cpp
src/bin/lttng-relayd/ctf-trace.cpp
src/bin/lttng-relayd/index.cpp
src/bin/lttng-relayd/session.cpp
src/bin/lttng-relayd/stream.cpp
src/bin/lttng-relayd/viewer-stream.cpp
src/bin/lttng-sessiond/agent.cpp
src/bin/lttng-sessiond/buffer-registry.cpp
src/bin/lttng-sessiond/cmd.cpp
src/bin/lttng-sessiond/consumer.cpp
src/bin/lttng-sessiond/event-notifier-error-accounting.cpp
src/bin/lttng-sessiond/event.cpp
src/bin/lttng-sessiond/lttng-syscall.cpp
src/bin/lttng-sessiond/session.cpp
src/bin/lttng-sessiond/snapshot.cpp
src/bin/lttng-sessiond/trace-ust.cpp
src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-registry-session.cpp
src/common/consumer/consumer.cpp
src/common/hashtable/hashtable.cpp
src/common/hashtable/hashtable.hpp

index 668a61e7a1a6b3674191a54964569bc6eba52982..2de3abe2d8cacd92684f51e05b0bcde645adacba 100644 (file)
@@ -32,7 +32,7 @@ struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connectio
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(relay_connections_ht, (void *) ((unsigned long) sock), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (!node) {
                DBG2("Relay connection by sock %d not found", sock);
                goto end;
index cde9f3927e381297b3f3b8bd53a00532ea2f2e98..81c5a770719a4c1f0fbe85f19fcc03c950d73534 100644 (file)
@@ -152,7 +152,7 @@ struct ctf_trace *ctf_trace_get_by_path_or_create(struct relay_session *session,
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(session->ctf_traces_ht, subpath, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (!node) {
                DBG("CTF Trace path %s not found", subpath);
                goto end;
index e3b8bde8230717a4f5e225d124f307aba135a4f1..7fd94ac43c8d79831ca8f064f62303fca8e597dc 100644 (file)
@@ -122,7 +122,7 @@ struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream,
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(stream->indexes_ht, &net_seq_num, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node) {
                index = lttng::utils::container_of(node, &relay_index::index_n);
        } else {
index 8ac4a510dc263f552e2b584256b328986c0e8aad..19f1936f229684f3a6f7a6c1e81a787bab346e4f 100644 (file)
@@ -457,7 +457,7 @@ struct relay_session *session_get_by_id(uint64_t id)
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(sessions_ht, &id, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                DBG("Session find by ID %" PRIu64 " id NOT found", id);
                goto end;
index a0935231d039280598ad538dfcaaa2f8189d3c27..5390c49bb6d59523fb999b9c1c6b543107733b55 100644 (file)
@@ -50,7 +50,7 @@ struct relay_stream *stream_get_by_id(uint64_t stream_id)
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(relay_streams_ht, &stream_id, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                DBG("Relay stream %" PRIu64 " not found", stream_id);
                goto end;
index 9ca54e67ea49b7be778cf054579ca54004289bcb..8830dae7aabe547637b757b30914abb063012e15 100644 (file)
@@ -265,7 +265,7 @@ struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id)
 
        lttng::urcu::read_lock_guard read_lock;
        lttng_ht_lookup(viewer_streams_ht, &id, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                DBG("Relay viewer stream %" PRIu64 " not found", id);
                goto end;
index 210ec9b0c6f2f997cab78ad26c6165192ea18360..5c080ca51d8c3eb9c713e4f3133d46201da71a3a 100644 (file)
@@ -1004,7 +1004,7 @@ struct agent_app *agent_find_app_by_sock(int sock)
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(the_agent_apps_ht_by_sock, (void *) ((unsigned long) sock), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                goto error;
        }
@@ -1375,7 +1375,7 @@ struct agent_event *agent_find_event(const char *name,
                        ht_match_event,
                        &key,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                goto error;
        }
@@ -1624,7 +1624,7 @@ struct agent *agent_find_by_event_notifier_domain(enum lttng_domain_type domain_
             lttng_domain_type_str(domain_type));
 
        lttng_ht_lookup(the_trigger_agents_ht_by_domain, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                goto end;
        }
index b840a7fa91ef0b69931a0f8c2f59c97389d31073..8e241feb626b89b8667221011ca17fcbbe6df706 100644 (file)
@@ -205,7 +205,7 @@ struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id, uint32_t bits_pe
 
        /* Custom lookup function since it's a different key. */
        cds_lfht_lookup(ht->ht, ht->hash_fct(&key, lttng_ht_seed), ht->match_fct, &key, &iter.iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                goto end;
        }
@@ -318,7 +318,7 @@ struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id)
        DBG3("Buffer registry per PID find id: %" PRIu64, session_id);
 
        lttng_ht_lookup(ht, &session_id, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                goto end;
        }
@@ -473,7 +473,7 @@ struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key, struct buffer_r
        }
 
        lttng_ht_lookup(ht, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                goto end;
        }
index ee96fc8285913b2fdf5cc75015478548d0b953b0..8817b45684528a0d9405209d3209d838a1e1cd6c 100644 (file)
@@ -407,7 +407,7 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name,
        lttng::urcu::read_lock_guard read_lock;
 
        lttng_ht_lookup(ust_global->channels, (void *) channel_name, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                ret_code = LTTNG_ERR_UST_CHAN_NOT_FOUND;
                goto error;
index 9e7e0536325eb2a398b4f374ecf0d6c695a0598e..9629182bafc269c888d0a4cda15aba060ea51408 100644 (file)
@@ -406,7 +406,7 @@ struct consumer_socket *consumer_find_socket(int key, const struct consumer_outp
        }
 
        lttng_ht_lookup(consumer->socks, (void *) ((unsigned long) key), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node != nullptr) {
                socket = lttng::utils::container_of(node, &consumer_socket::node);
        }
index 7fa54bc93080b54c361306ca3405b580f8b58f07..e22598223658b2a9c4ff4688b4ae5c90bb105191 100644 (file)
@@ -307,7 +307,7 @@ static enum event_notifier_error_accounting_status get_error_counter_index_for_t
        lttng::urcu::read_lock_guard read_guard;
 
        lttng_ht_lookup(state->indices_ht, &tracer_token, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node) {
                index_entry = lttng::utils::container_of(node, &index_ht_entry::node);
                *error_counter_index = index_entry->error_counter_index;
@@ -333,7 +333,7 @@ static struct ust_error_accounting_entry *ust_error_accounting_entry_find(struct
        uint64_t key = app->uid;
 
        lttng_ht_lookup(uid_ht, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node == nullptr) {
                entry = nullptr;
        } else {
@@ -1302,7 +1302,7 @@ void event_notifier_error_accounting_unregister_event_notifier(const struct lttn
        }
 
        lttng_ht_lookup(state->indices_ht, &tracer_token, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node) {
                int del_ret;
                struct index_ht_entry *index_entry =
index 462ed2f0db588fdd1ad37debd9bf6d2609ef079c..c0b1aeebe75fc6df90e976d55205fe646bd7daff 100644 (file)
@@ -274,7 +274,7 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
                        trace_ust_ht_match_event_by_name,
                        event_name,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                DBG2("Trace UST event NOT found by name %s", event_name);
                ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
@@ -304,7 +304,7 @@ int event_ust_disable_tracepoint(struct ltt_ust_session *usess,
                /* Get next duplicate event by name. */
                cds_lfht_next_duplicate(
                        ht->ht, trace_ust_ht_match_event_by_name, event_name, &iter.iter);
-               node = lttng_ht_iter_get_node_str(&iter);
+               node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        } while (node);
 
        ret = LTTNG_OK;
@@ -877,7 +877,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, const
 
        lttng::urcu::read_lock_guard read_lock;
        agent_find_events_by_name(event_name, agt, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
 
        if (node == nullptr) {
                DBG2("Event agent NOT found by name %s", event_name);
@@ -895,7 +895,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt, const
 
                /* Get next duplicate agent event by name. */
                agent_event_next_duplicate(event_name, agt, &iter);
-               node = lttng_ht_iter_get_node_str(&iter);
+               node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        } while (node);
 end:
        return ret;
index 821bbaa34f80b6e1c6d572192909c0ec0257aab2..06f4ab1fb991a0ca0b81c6ff2dd1fd5b78a224ba 100644 (file)
@@ -215,7 +215,7 @@ static struct syscall *lookup_syscall(struct lttng_ht *ht, const char *name)
        LTTNG_ASSERT(name);
 
        lttng_ht_lookup(ht, (void *) name, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node) {
                ksyscall = lttng::utils::container_of(node, &syscall::node);
        }
index 97391ad98f1ae1d9006cf5b316b011abe719fdf7..cfa8c8b0384b134db1183282dab8111fe55234e4 100644 (file)
@@ -115,7 +115,7 @@ struct ltt_session *session_find_by_id(uint64_t id)
        }
 
        lttng_ht_lookup(ltt_sessions_ht_by_id, &id, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node == nullptr) {
                goto end;
        }
@@ -1407,7 +1407,7 @@ bool sample_session_id_by_name(const char *name, uint64_t *id)
        }
 
        lttng_ht_lookup(ltt_sessions_ht_by_name, name, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                found = false;
                goto end;
index 4f72306ac1ea18e0bb9807acc501e5402da6bcd7..f9ab929d64905ff1f57d431e2fd0b76d4aefebe1 100644 (file)
@@ -277,7 +277,7 @@ struct snapshot_output *snapshot_find_output_by_id(uint32_t id, struct snapshot
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(snapshot->output_ht, (void *) ((unsigned long) id), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (!node) {
                DBG3("Snapshot output not found with id %" PRId32, id);
                goto error;
index e4fdef9ad159d686b1f3bd4f84fa453e7438c8ce..bffd2900b3e8c93c8bd7af9f77ffc791a133ffed 100644 (file)
@@ -174,7 +174,7 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, cons
                name = DEFAULT_CHANNEL_NAME;
 
        lttng_ht_lookup(ht, (void *) name, &iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                goto error;
        }
@@ -218,7 +218,7 @@ struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
                        trace_ust_ht_match_event,
                        &key,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                goto error;
        }
@@ -254,7 +254,7 @@ struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
        key = domain_type;
 
        lttng_ht_lookup(session->agents, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                goto end;
        }
@@ -785,7 +785,7 @@ id_tracker_lookup(struct ust_id_tracker *id_tracker, int id, struct lttng_ht_ite
        struct lttng_ht_node_ulong *node;
 
        lttng_ht_lookup(id_tracker->ht, (void *) _id, iter);
-       node = lttng_ht_iter_get_node_ulong(iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(iter);
        if (node) {
                return lttng::utils::container_of(node, &ust_id_tracker_node::node);
        } else {
index 6e7b3f5e1deadc0af7fd1203ccfef20d81805e35..1e54f3a4068fef4b754c7c3d019514fd293640e7 100644 (file)
@@ -1456,7 +1456,7 @@ struct ust_app *ust_app_find_by_sock(int sock)
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(ust_app_ht_by_sock, (void *) ((unsigned long) sock), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                DBG2("UST app find by sock %d not found", sock);
                goto error;
@@ -1480,7 +1480,7 @@ static struct ust_app *find_app_by_notify_sock(int sock)
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(ust_app_ht_by_notify_sock, (void *) ((unsigned long) sock), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                DBG2("UST app find by notify sock %d not found", sock);
                goto error;
@@ -1527,7 +1527,7 @@ static struct ust_app_event *find_ust_app_event(struct lttng_ht *ht,
                        ht_match_ust_app_event,
                        &key,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (node == nullptr) {
                goto end;
        }
@@ -1555,7 +1555,7 @@ static struct ust_app_event_notifier_rule *find_ust_app_event_notifier_rule(stru
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(ht, &token, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node == nullptr) {
                DBG2("UST app event notifier rule token not found: token = %" PRIu64, token);
                goto end;
@@ -2540,7 +2540,7 @@ static struct ust_app_session *lookup_session_by_app(const struct ltt_ust_sessio
        struct lttng_ht_node_u64 *node;
 
        __lookup_session_by_app(usess, app, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node == nullptr) {
                goto error;
        }
@@ -2885,7 +2885,7 @@ static struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht,
                        ht_match_ust_app_ctx,
                        uctx,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (!node) {
                goto end;
        }
@@ -3012,7 +3012,7 @@ static int enable_ust_app_channel(struct ust_app_session *ua_sess,
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter);
-       ua_chan_node = lttng_ht_iter_get_node_str(&iter);
+       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (ua_chan_node == nullptr) {
                DBG2("Unable to find channel %s in ust session id %" PRIu64,
                     uchan->name,
@@ -3730,7 +3730,7 @@ static int ust_app_channel_allocate(struct ust_app_session *ua_sess,
 
        /* Lookup channel in the ust app session */
        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter);
-       ua_chan_node = lttng_ht_iter_get_node_str(&iter);
+       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (ua_chan_node != nullptr) {
                ua_chan = lttng::utils::container_of(ua_chan_node, &ust_app_channel::node);
                goto end;
@@ -3991,7 +3991,7 @@ struct ust_app *ust_app_find_by_pid(pid_t pid)
        struct lttng_ht_iter iter;
 
        lttng_ht_lookup(ust_app_ht, (void *) ((unsigned long) pid), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                DBG2("UST app no found with pid %d", pid);
                goto error;
@@ -4433,7 +4433,7 @@ void ust_app_unregister_by_socket(int sock_fd)
 
        /* Get the node reference for a call_rcu */
        lttng_ht_lookup(ust_app_ht_by_sock, (void *) ((unsigned long) sock_fd), &ust_app_sock_iter);
-       node = lttng_ht_iter_get_node_ulong(&ust_app_sock_iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&ust_app_sock_iter);
        assert(node);
 
        app = caa_container_of(node, struct ust_app, sock_n);
@@ -4873,7 +4873,7 @@ int ust_app_disable_channel_glb(struct ltt_ust_session *usess, struct ltt_ust_ch
 
                        /* Get channel */
                        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-                       ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+                       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                        /* If the session if found for the app, the channel must be there */
                        LTTNG_ASSERT(ua_chan_node);
 
@@ -4979,7 +4979,7 @@ int ust_app_disable_event_glb(struct ltt_ust_session *usess,
 
                        /* Lookup channel in the ust app session */
                        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-                       ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+                       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                        if (ua_chan_node == nullptr) {
                                DBG2("Channel %s not found in session id %" PRIu64
                                     " for app pid %d."
@@ -5142,7 +5142,7 @@ int ust_app_enable_event_glb(struct ltt_ust_session *usess,
 
                        /* Lookup channel in the ust app session */
                        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-                       ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+                       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                        /*
                         * It is possible that the channel cannot be found is
                         * the channel/event creation occurs concurrently with
@@ -5232,7 +5232,7 @@ int ust_app_create_event_glb(struct ltt_ust_session *usess,
 
                        /* Lookup channel in the ust app session */
                        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-                       ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+                       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                        /* If the channel is not found, there is a code flow error */
                        LTTNG_ASSERT(ua_chan_node);
 
@@ -5777,7 +5777,7 @@ static int destroy_trace(struct ltt_ust_session *usess, struct ust_app *app)
        }
 
        __lookup_session_by_app(usess, app, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node == nullptr) {
                /* Session is being or is deleted. */
                goto end;
@@ -5922,7 +5922,7 @@ static int find_or_create_ust_app_channel(struct ltt_ust_session *usess,
        struct lttng_ht_node_str *ua_chan_node;
 
        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &iter);
-       ua_chan_node = lttng_ht_iter_get_node_str(&iter);
+       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (ua_chan_node) {
                *ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
                goto end;
@@ -6363,7 +6363,7 @@ int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
 
                        /* Lookup channel in the ust app session */
                        lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-                       ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+                       ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                        if (ua_chan_node == nullptr) {
                                goto next_app;
                        }
@@ -6452,7 +6452,7 @@ static struct ust_app_session *find_session_by_objd(struct ust_app *app, int obj
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(app->ust_sessions_objd, (void *) ((unsigned long) objd), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                DBG2("UST app session find by objd %d not found", objd);
                goto error;
@@ -6479,7 +6479,7 @@ static struct ust_app_channel *find_channel_by_objd(struct ust_app *app, int obj
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(app->ust_objd, (void *) ((unsigned long) objd), &iter);
-       node = lttng_ht_iter_get_node_ulong(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
        if (node == nullptr) {
                DBG2("UST app channel find by objd %d not found", objd);
                goto error;
@@ -7461,7 +7461,7 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
 
                /* Get channel */
                lttng_ht_lookup(ua_sess->channels, (void *) uchan->name, &uiter);
-               ua_chan_node = lttng_ht_iter_get_node_str(&uiter);
+               ua_chan_node = lttng_ht_iter_get_node<lttng_ht_node_str>(&uiter);
                /* If the session is found for the app, the channel must be there */
                LTTNG_ASSERT(ua_chan_node);
 
index 7c091f7e694649aab325be0bb8a7e4a921057723..8441b4e2c9a4a25e03f4284160bc8056ae6c80f9 100644 (file)
@@ -494,7 +494,7 @@ lttng::sessiond::ust::registry_channel& lsu::registry_session::channel(uint64_t
        ASSERT_LOCKED(_lock);
 
        lttng_ht_lookup(_channels.get(), &channel_key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (!node) {
                LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
                        "Invalid channel key provided: channel key = {}", channel_key));
@@ -718,7 +718,7 @@ lsu::registry_session::enumeration(const char *enum_name, uint64_t enum_id) cons
                        ht_match_enum_id,
                        &reg_enum_lookup,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (!node) {
                LTTNG_THROW_PROTOCOL_ERROR(lttng::format(
                        "Unknown enumeration referenced by application event field: enum name = `{}`, enum id = {}",
@@ -752,7 +752,7 @@ lsu::registry_session::_lookup_enum(const lsu::registry_enum *reg_enum_lookup) c
                        ht_match_enum,
                        reg_enum_lookup,
                        &iter.iter);
-       node = lttng_ht_iter_get_node_str(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
        if (!node) {
                goto end;
        }
index 1da243601cd7ff3c72fc8febb5d6c11f2f150c4b..ed25a42ea8724b33afbc1651efd760b29d9af876 100644 (file)
@@ -202,7 +202,7 @@ static struct lttng_consumer_stream *find_stream(uint64_t key, struct lttng_ht *
        lttng::urcu::read_lock_guard read_lock;
 
        lttng_ht_lookup(ht, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node != nullptr) {
                stream = lttng::utils::container_of(node, &lttng_consumer_stream::node);
        }
@@ -247,7 +247,7 @@ struct lttng_consumer_channel *consumer_find_channel(uint64_t key)
        }
 
        lttng_ht_lookup(the_consumer_data.channel_ht, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node != nullptr) {
                channel = lttng::utils::container_of(node, &lttng_consumer_channel::node);
        }
@@ -629,7 +629,7 @@ static int add_relayd(struct consumer_relayd_sock_pair *relayd)
        ASSERT_RCU_READ_LOCKED();
 
        lttng_ht_lookup(the_consumer_data.relayd_ht, &relayd->net_seq_idx, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node != nullptr) {
                goto end;
        }
@@ -690,7 +690,7 @@ struct consumer_relayd_sock_pair *consumer_find_relayd(uint64_t key)
        }
 
        lttng_ht_lookup(the_consumer_data.relayd_ht, &key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        if (node != nullptr) {
                relayd = lttng::utils::container_of(node, &consumer_relayd_sock_pair::node);
        }
@@ -2185,7 +2185,7 @@ void consumer_add_metadata_stream(struct lttng_consumer_stream *stream)
         * state. This should NEVER happen.
         */
        lttng_ht_lookup(ht, &stream->key, &iter);
-       node = lttng_ht_iter_get_node_u64(&iter);
+       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
        LTTNG_ASSERT(!node);
 
        /*
@@ -2411,7 +2411,7 @@ void *consumer_thread_metadata_poll(void *data)
 
                                lttng_ht_lookup(metadata_ht, &tmp_id, &iter);
                        }
-                       node = lttng_ht_iter_get_node_u64(&iter);
+                       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
                        LTTNG_ASSERT(node);
 
                        stream = caa_container_of(node, struct lttng_consumer_stream, node);
@@ -3067,7 +3067,7 @@ void *consumer_thread_channel_poll(void *data)
 
                                lttng_ht_lookup(channel_ht, &tmp_id, &iter);
                        }
-                       node = lttng_ht_iter_get_node_u64(&iter);
+                       node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
                        LTTNG_ASSERT(node);
 
                        chan = caa_container_of(node, struct lttng_consumer_channel, wait_fd_node);
index 29d3ac499715f1e9da4e8eb8d7b4c79b2c786157..be7e77342df8b6d7c297f135c87194c9921cf47d 100644 (file)
@@ -492,64 +492,4 @@ unsigned long lttng_ht_get_count(struct lttng_ht *ht)
        cds_lfht_count_nodes(ht->ht, &scb, &count, &sca);
 
        return count;
-}
-
-/*
- * Return lttng ht string node from iterator.
- */
-struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter)
-{
-       struct cds_lfht_node *node;
-
-       LTTNG_ASSERT(iter);
-       node = cds_lfht_iter_get_node(&iter->iter);
-       if (!node) {
-               return nullptr;
-       }
-       return lttng::utils::container_of(node, &lttng_ht_node_str::node);
-}
-
-/*
- * Return lttng ht unsigned long node from iterator.
- */
-struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter)
-{
-       struct cds_lfht_node *node;
-
-       LTTNG_ASSERT(iter);
-       node = cds_lfht_iter_get_node(&iter->iter);
-       if (!node) {
-               return nullptr;
-       }
-       return lttng::utils::container_of(node, &lttng_ht_node_ulong::node);
-}
-
-/*
- * Return lttng ht unsigned long node from iterator.
- */
-struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter)
-{
-       struct cds_lfht_node *node;
-
-       LTTNG_ASSERT(iter);
-       node = cds_lfht_iter_get_node(&iter->iter);
-       if (!node) {
-               return nullptr;
-       }
-       return lttng::utils::container_of(node, &lttng_ht_node_u64::node);
-}
-
-/*
- * Return lttng ht stream and index id node from iterator.
- */
-struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter)
-{
-       struct cds_lfht_node *node;
-
-       LTTNG_ASSERT(iter);
-       node = cds_lfht_iter_get_node(&iter->iter);
-       if (!node) {
-               return nullptr;
-       }
-       return lttng::utils::container_of(node, &lttng_ht_node_two_u64::node);
-}
+}
\ No newline at end of file
index ac1af7eed6669824dd981b7f84e91d8984ae2918..db258e4d997848d5240fad3d1ffa2196c3d60f47 100644 (file)
@@ -113,9 +113,17 @@ void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter);
 
 unsigned long lttng_ht_get_count(struct lttng_ht *ht);
 
-struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter);
-struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *iter);
-struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter);
-struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_iter *iter);
+template <class NodeType>
+NodeType *lttng_ht_iter_get_node(const lttng_ht_iter *iter)
+{
+       LTTNG_ASSERT(iter);
+
+       auto node = iter->iter.node;
+       if (!node) {
+               return nullptr;
+       }
+
+       return lttng::utils::container_of(node, &NodeType::node);
+}
 
 #endif /* _LTT_HT_H */
This page took 0.039336 seconds and 4 git commands to generate.