[lttng-dev] [PATCH lttng-ust 7/8] Rename lttng_ust_enum_get to lttng_ust_enum_get_from_desc

Francis Deslauriers francis.deslauriers at efficios.com
Fri Feb 2 19:48:10 UTC 2018


Change the prototype to take a descriptor instead of a char *.
Now that provider names can have duplicates enum names are not
necessarily unique.

Signed-off-by: Francis Deslauriers <francis.deslauriers at efficios.com>
---
 include/lttng/ust-events.h         |  5 +++--
 liblttng-ust-comm/lttng-ust-comm.c |  3 +--
 liblttng-ust/lttng-events.c        | 14 ++++++--------
 liblttng-ust/ust-core.c            | 11 +++++------
 4 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h
index 019b0eb..8673350 100644
--- a/include/lttng/ust-events.h
+++ b/include/lttng/ust-events.h
@@ -731,8 +731,9 @@ int lttng_session_active(void);
 typedef int (*t_statedump_func_ptr)(struct lttng_session *session);
 void lttng_handle_pending_statedump(void *owner);
 struct cds_list_head *_lttng_get_sessions(void);
-struct lttng_enum *lttng_ust_enum_get(struct lttng_session *session,
-		const char *enum_name);
+
+struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
+		const struct lttng_enum_desc *enum_desc);
 
 void lttng_ust_dl_update(void *ip);
 void lttng_ust_fixup_fd_tracker_tls(void);
diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c
index 9fe6d28..d95e31d 100644
--- a/liblttng-ust-comm/lttng-ust-comm.c
+++ b/liblttng-ust-comm/lttng-ust-comm.c
@@ -874,8 +874,7 @@ int serialize_basic_type(struct lttng_session *session,
 		if (session) {
 			const struct lttng_enum *_enum;
 
-			_enum = lttng_ust_enum_get(session,
-					lbt->enumeration.desc->name);
+			_enum = lttng_ust_enum_get_from_desc(session, lbt->enumeration.desc);
 			if (!_enum)
 				return -EINVAL;
 			ubt->enumeration.id = _enum->id;
diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c
index 2b679b5..07385d7 100644
--- a/liblttng-ust/lttng-events.c
+++ b/liblttng-ust/lttng-events.c
@@ -257,21 +257,19 @@ int lttng_enum_create(const struct lttng_enum_desc *desc,
 	const char *enum_name = desc->name;
 	struct lttng_enum *_enum;
 	struct cds_hlist_head *head;
-	struct cds_hlist_node *node;
 	int ret = 0;
 	size_t name_len = strlen(enum_name);
 	uint32_t hash;
 	int notify_socket;
 
+	/* Check if this enum is already registered for this session. */
 	hash = jhash(enum_name, name_len, 0);
 	head = &session->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
-	cds_hlist_for_each_entry(_enum, node, head, hlist) {
-		assert(_enum->desc);
-		if (!strncmp(_enum->desc->name, desc->name,
-				LTTNG_UST_SYM_NAME_LEN - 1)) {
-			ret = -EEXIST;
-			goto exist;
-		}
+
+	_enum = lttng_ust_enum_get_from_desc(session, desc);
+	if (_enum) {
+		ret = -EEXIST;
+		goto exist;
 	}
 
 	notify_socket = lttng_get_notify_socket(session->owner);
diff --git a/liblttng-ust/ust-core.c b/liblttng-ust/ust-core.c
index 5355f5c..76f729a 100644
--- a/liblttng-ust/ust-core.c
+++ b/liblttng-ust/ust-core.c
@@ -63,21 +63,20 @@ void lttng_transport_unregister(struct lttng_transport *transport)
 /*
  * Needed by comm layer.
  */
-struct lttng_enum *lttng_ust_enum_get(struct lttng_session *session,
-		const char *enum_name)
+struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
+		const struct lttng_enum_desc *enum_desc)
 {
 	struct lttng_enum *_enum;
 	struct cds_hlist_head *head;
 	struct cds_hlist_node *node;
-	size_t name_len = strlen(enum_name);
+	size_t name_len = strlen(enum_desc->name);
 	uint32_t hash;
 
-	hash = jhash(enum_name, name_len, 0);
+	hash = jhash(enum_desc->name, name_len, 0);
 	head = &session->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
 	cds_hlist_for_each_entry(_enum, node, head, hlist) {
 		assert(_enum->desc);
-		if (!strncmp(_enum->desc->name, enum_name,
-				LTTNG_UST_SYM_NAME_LEN - 1))
+		if (_enum->desc == enum_desc)
 			return _enum;
 	}
 	return NULL;
-- 
2.7.4



More information about the lttng-dev mailing list