|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] tools/xenstore: add hashtable_replace() function
commit a9d11f0adc2c123cf37e3ff5d91f1414a9377d3a
Author: Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Mon Aug 14 09:46:51 2023 +0200
Commit: Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Fri Aug 18 13:44:48 2023 +0100
tools/xenstore: add hashtable_replace() function
For an effective way to replace a hashtable entry add a new function
hashtable_replace().
This is in preparation to replace TDB with a more simple data storage.
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
tools/xenstore/hashtable.c | 19 +++++++++++++++++++
tools/xenstore/hashtable.h | 16 ++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c
index 88e14c4c57..0c26a09567 100644
--- a/tools/xenstore/hashtable.c
+++ b/tools/xenstore/hashtable.c
@@ -205,6 +205,25 @@ void *hashtable_search(const struct hashtable *h, const
void *k)
return e ? e->v : NULL;
}
+int hashtable_replace(struct hashtable *h, const void *k, void *v)
+{
+ struct entry *e;
+
+ e = hashtable_search_entry(h, k);
+ if (!e)
+ return ENOENT;
+
+ if (h->flags & HASHTABLE_FREE_VALUE)
+ {
+ talloc_free(e->v);
+ talloc_steal(e, v);
+ }
+
+ e->v = v;
+
+ return 0;
+}
+
void
hashtable_remove(struct hashtable *h, const void *k)
{
diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h
index e208d439a2..336540413b 100644
--- a/tools/xenstore/hashtable.h
+++ b/tools/xenstore/hashtable.h
@@ -45,6 +45,22 @@ create_hashtable(const void *ctx, const char *name,
int
hashtable_add(struct hashtable *h, const void *k, void *v);
+/*****************************************************************************
+ * hashtable_replace
+
+ * @name hashtable_nsert
+ * @param h the hashtable to insert into
+ * @param k the key - hashtable claims ownership and will free on removal
+ * @param v the value - does not claim ownership
+ * @return zero for successful insertion
+ *
+ * This function does check for an entry being present before replacing it
+ * with a new value.
+ */
+
+int
+hashtable_replace(struct hashtable *h, const void *k, void *v);
+
/*****************************************************************************
* hashtable_search
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |