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>
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;
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;
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 {
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;
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;
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;
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;
}
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;
}
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;
}
/* 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;
}
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;
}
}
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;
}
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;
}
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);
}
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;
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 {
}
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 =
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;
/* 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;
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);
/* 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;
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);
}
}
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;
}
}
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;
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;
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;
}
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;
}
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;
}
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 {
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;
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;
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;
}
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;
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;
}
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;
}
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,
/* 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;
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;
/* 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);
/* 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);
/* 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."
/* 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
/* 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);
}
__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;
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;
/* 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;
}
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;
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;
/* 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);
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));
ht_match_enum_id,
®_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 = {}",
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;
}
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, <tng_consumer_stream::node);
}
}
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, <tng_consumer_channel::node);
}
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;
}
}
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);
}
* 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);
/*
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);
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);
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, <tng_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, <tng_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, <tng_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, <tng_ht_node_two_u64::node);
-}
+}
\ No newline at end of file
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 */