From 810185f3a90e717e2a482b4555f90f4d4f6d7bbf Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 22 Apr 2021 11:31:50 -0400 Subject: [PATCH] Move lttng_ust_enum_get_from_desc to libcommon It is used by both liblttng-ust and liblttng-ust-ctl and contains no shared state. Change-Id: I8079e2c81cf72fe2075205608cf5e99aa07f6dfd Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- src/common/Makefile.am | 1 + src/common/events.c | 27 +++++++++++++++++++++++++++ src/lib/lttng-ust/ust-core.c | 22 ---------------------- 3 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 src/common/events.c diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 777764fd..ce427655 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -139,6 +139,7 @@ libsnprintf_la_SOURCES = \ libcommon_la_SOURCES = \ elf.c \ elf.h \ + events.c \ getenv.c \ getenv.h \ logging.c \ diff --git a/src/common/events.c b/src/common/events.c new file mode 100644 index 00000000..f70a1b4b --- /dev/null +++ b/src/common/events.c @@ -0,0 +1,27 @@ + +#include + +#include "common/events.h" +#include "common/jhash.h" + +/* + * Needed by comm layer. + */ +struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session, + const struct lttng_ust_enum_desc *enum_desc) +{ + struct lttng_enum *_enum; + struct cds_hlist_head *head; + struct cds_hlist_node *node; + size_t name_len = strlen(enum_desc->name); + uint32_t hash; + + hash = jhash(enum_desc->name, name_len, 0); + head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)]; + cds_hlist_for_each_entry(_enum, node, head, hlist) { + assert(_enum->desc); + if (_enum->desc == enum_desc) + return _enum; + } + return NULL; +} diff --git a/src/lib/lttng-ust/ust-core.c b/src/lib/lttng-ust/ust-core.c index d070124e..e547a497 100644 --- a/src/lib/lttng-ust/ust-core.c +++ b/src/lib/lttng-ust/ust-core.c @@ -86,28 +86,6 @@ void lttng_counter_transport_unregister(struct lttng_counter_transport *transpor cds_list_del(&transport->node); } -/* - * Needed by comm layer. - */ -struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session, - const struct lttng_ust_enum_desc *enum_desc) -{ - struct lttng_enum *_enum; - struct cds_hlist_head *head; - struct cds_hlist_node *node; - size_t name_len = strlen(enum_desc->name); - uint32_t hash; - - hash = jhash(enum_desc->name, name_len, 0); - head = &session->priv->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)]; - cds_hlist_for_each_entry(_enum, node, head, hlist) { - assert(_enum->desc); - if (_enum->desc == enum_desc) - return _enum; - } - return NULL; -} - size_t lttng_ust_dummy_get_size(void *priv __attribute__((unused)), struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)), size_t offset) -- 2.34.1