* [dpdk-dev] [PATCH] librte_hash: new hash del abi to returns stored value
@ 2018-05-14 21:09 Vijaya Mohan Guvva
0 siblings, 0 replies; only message in thread
From: Vijaya Mohan Guvva @ 2018-05-14 21:09 UTC (permalink / raw)
To: Bruce Richardson, Pablo de Lara; +Cc: dev, Vijaya Mohan Guvva
Add a new key delete interface rte_hash_del_key_with_hash_data to
delete the key from hash and return the value stored. This is useful
for hash users to free the data stored in the table after key delete
and to avoid maintaining a user data array in the dpdk application.
Signed-off-by: Vijaya Mohan Guvva <vguvva@caviumnetworks.com>
---
lib/librte_hash/rte_cuckoo_hash.c | 20 +++++++++++++++++---
lib/librte_hash/rte_hash.h | 24 ++++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index a07543a..693b543 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -808,7 +808,7 @@ struct rte_hash *
static inline int32_t
__rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key,
- hash_sig_t sig)
+ hash_sig_t sig, void **data)
{
uint32_t bucket_idx;
hash_sig_t alt_hash;
@@ -827,6 +827,8 @@ struct rte_hash *
k = (struct rte_hash_key *) ((char *)keys +
bkt->key_idx[i] * h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+ if (data != NULL)
+ *data = k->pdata;
remove_entry(h, bkt, i);
/*
@@ -852,6 +854,8 @@ struct rte_hash *
k = (struct rte_hash_key *) ((char *)keys +
bkt->key_idx[i] * h->key_entry_size);
if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+ if (data != NULL)
+ *data = k->pdata;
remove_entry(h, bkt, i);
/*
@@ -869,18 +873,28 @@ struct rte_hash *
}
int32_t
+rte_hash_del_key_with_hash_data(const struct rte_hash *h,
+ const void *key, hash_sig_t sig, void **data)
+{
+ RETURN_IF_TRUE(((h == NULL) || (key == NULL) ||
+ (data == NULL)), -EINVAL);
+ return __rte_hash_del_key_with_hash(h, key, sig, data);
+}
+
+int32_t
rte_hash_del_key_with_hash(const struct rte_hash *h,
const void *key, hash_sig_t sig)
{
RETURN_IF_TRUE(((h == NULL) || (key == NULL)), -EINVAL);
- return __rte_hash_del_key_with_hash(h, key, sig);
+ return __rte_hash_del_key_with_hash(h, key, sig, NULL);
}
int32_t
rte_hash_del_key(const struct rte_hash *h, const void *key)
{
RETURN_IF_TRUE(((h == NULL) || (key == NULL)), -EINVAL);
- return __rte_hash_del_key_with_hash(h, key, rte_hash_hash(h, key));
+ return __rte_hash_del_key_with_hash(h, key,
+ rte_hash_hash(h, key), NULL);
}
int
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index f71ca9f..73e1efb 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -222,6 +222,30 @@ struct rte_hash *
rte_hash_del_key(const struct rte_hash *h, const void *key);
/**
+ * Remove a key from an existing hash table and return the data stored.
+ * This operation is not multi-thread safe
+ * and should only be called from one thread.
+ *
+ * @param h
+ * Hash table to remove the key from.
+ * @param key
+ * Key to remove from the hash table.
+ * @param sig
+ * Precomputed hash value for 'key'.
+ * @param data
+ * Output with pointer to data returned from the hash table.
+ * @return
+ * - -EINVAL if the parameters are invalid.
+ * - -ENOENT if the key is not found.
+ * - A positive value that can be used by the caller as an offset into an
+ * array of user data. This value is unique for this key, and is the same
+ * value that was returned when the key was added.
+ */
+int32_t
+rte_hash_del_key_with_hash_data(const struct rte_hash *h, const void *key,
+ hash_sig_t sig, void **data);
+
+/**
* Remove a key from an existing hash table.
* This operation is not multi-thread safe
* and should only be called from one thread.
--
1.8.3.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-05-14 21:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14 21:09 [dpdk-dev] [PATCH] librte_hash: new hash del abi to returns stored value Vijaya Mohan Guvva
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).