summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorSusant Sahani <ssahani@vmware.com>2020-08-28 12:38:18 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-09-01 12:32:48 +0200
commitb7847e05f53cf3f071d92e9c3b46652d8396c6ed (patch)
tree6fe7818176d7af9f8f90c5bf6a24ae20ad199615 /src/basic
parentMerge pull request #16885 from keszybz/rework-cache-timestamps (diff)
downloadsystemd-b7847e05f53cf3f071d92e9c3b46652d8396c6ed.tar.xz
systemd-b7847e05f53cf3f071d92e9c3b46652d8396c6ed.zip
basic: Introduce ordered_hashmap_ensure_put
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.c10
-rw-r--r--src/basic/hashmap.h3
2 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 67c4391230..e0319031d6 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -848,6 +848,16 @@ int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBU
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
}
+int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
+ int r;
+
+ r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
+ if (r < 0)
+ return r;
+
+ return ordered_hashmap_put(*h, key, value);
+}
+
static void hashmap_free_no_clear(HashmapBase *h) {
assert(!h->has_indirect);
assert(h->n_direct_entries == 0);
diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h
index 6009441621..c8f82b1df6 100644
--- a/src/basic/hashmap.h
+++ b/src/basic/hashmap.h
@@ -137,6 +137,9 @@ int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops
#define hashmap_ensure_allocated(h, ops) _hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
#define ordered_hashmap_ensure_allocated(h, ops) _ordered_hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
+int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
+#define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
+
IteratedCache *_hashmap_iterated_cache_new(HashmapBase *h);
static inline IteratedCache *hashmap_iterated_cache_new(Hashmap *h) {
return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));