From 9e4946b324a8480b35c861e96199881b314ea825 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Mon, 8 Jul 2019 14:47:44 -0400 Subject: vppinfra: bihash add-but-do-not-overwrite semantics If is_add=2, fail w/ return value -2 if the key exists instead of overwriting the (key,value) pair. Type: feature Change-Id: I00a3c194a381c68090369c31d6c6f9870cfe0a62 Signed-off-by: Dave Barach --- src/vppinfra/bihash_template.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/vppinfra') diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c index bf6be83b2e0..cd75a7a9be9 100644 --- a/src/vppinfra/bihash_template.c +++ b/src/vppinfra/bihash_template.c @@ -519,6 +519,13 @@ static inline int BV (clib_bihash_add_del_inline) { if (BV (clib_bihash_key_compare) (v->kvp[i].key, add_v->key)) { + /* Add but do not overwrite? */ + if (is_add == 2) + { + BV (clib_bihash_unlock_bucket) (b); + return (-2); + } + CLIB_MEMORY_BARRIER (); /* Add a delay */ clib_memcpy_fast (&(v->kvp[i]), add_v, sizeof (*add_v)); BV (clib_bihash_unlock_bucket) (b); -- cgit 1.2.3-korg