DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomas Vestelind <tomas.vestelind@gmail.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] hash: added rte_hash_clear that clears all keys
Date: Tue, 12 Aug 2014 23:47:57 +0200	[thread overview]
Message-ID: <1407880077-15038-1-git-send-email-tomas.vestelind@gmail.com> (raw)

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(+)

diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c
index 2108c4f..917a6c1 100644
--- a/lib/librte_hash/rte_hash.c
+++ b/lib/librte_hash/rte_hash.c
@@ -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;
+        }
+    }
+}
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index e0fb28f..b84137e 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -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
-- 
1.7.10.4

             reply	other threads:[~2014-08-12 21:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 21:47 Tomas Vestelind [this message]
2015-03-06 11:10 Bruce Richardson
2015-03-06 12:02 ` Tomas Vestelind
2015-03-06 12:53   ` Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407880077-15038-1-git-send-email-tomas.vestelind@gmail.com \
    --to=tomas.vestelind@gmail.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).