[dpdk-dev] hash: added rte_hash_clear that clears all keys
Commit Message
I added rte_hash_clear which clear the map from all previously added
keys.
Signed-off-by: Tomas Vestelind <tomas.vestelind@gmail.com>
---
lib/librte_hash/rte_hash.c | 14 ++++++++++++++
lib/librte_hash/rte_hash.h | 10 ++++++++++
2 files changed, 24 insertions(+)
@@ -507,3 +507,17 @@ rte_hash_keys(const struct rte_hash *h, void *keys)
return found_keys;
}
+
+void
+rte_hash_clear(const struct rte_hash *h)
+{
+ unsigned int bucket, entry;
+
+ /* Clear all entries by invalidating each signature */
+ for (bucket = 0; bucket < h->num_buckets; bucket++) {
+ hash_sig_t *sig = get_sig_tbl_bucket(h, bucket);
+ for (entry = 0; entry < h->bucket_entries; entry++) {
+ sig[entry] = NULL_SIGNATURE;
+ }
+ }
+}
@@ -318,6 +318,16 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,
*/
unsigned int
rte_hash_keys(const struct rte_hash *h, void *keys);
+
+/**
+ * Clear all keys. This operation is not multi-thread safe and should only be
+ * called from one thread.
+ *
+ * @param h
+ * Hash table to clear.
+ */
+void
+rte_hash_clear(const struct rte_hash *h);
#ifdef __cplusplus
}
#endif