[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230609151332.263152-2-pctammela@mojatatu.com>
Date: Fri, 9 Jun 2023 12:13:29 -0300
From: Pedro Tammela <pctammela@...atatu.com>
To: netdev@...r.kernel.org
Cc: tgraf@...g.ch,
herbert@...dor.apana.org.au,
davem@...emloft.net,
dsahern@...nel.org,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
Pedro Tammela <pctammela@...atatu.com>
Subject: [RFC PATCH net-next 1/4] rhashtable: add length helper for rhashtable and rhltable
Instead of having users open code the rhashtable length like:
atomic_read(&ht->nelems)
Provide a helper for both flavours of rhashtables.
Signed-off-by: Pedro Tammela <pctammela@...atatu.com>
---
include/linux/rhashtable.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 5b5357c0bd8c..aac803491916 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -1283,4 +1283,20 @@ static inline void rhltable_destroy(struct rhltable *hlt)
return rhltable_free_and_destroy(hlt, NULL, NULL);
}
+/**
+ * rhashtable_len - hash table length
+ * @ht: the hash table
+ *
+ * Returns the number of elements in the hash table
+ */
+static inline int rhashtable_len(struct rhashtable *ht)
+{
+ return atomic_read(&ht->nelems);
+}
+
+static inline int rhltable_len(struct rhltable *hlt)
+{
+ return rhashtable_len(&hlt->ht);
+}
+
#endif /* _LINUX_RHASHTABLE_H */
--
2.39.2
Powered by blists - more mailing lists