diff options
Diffstat (limited to 'src/vppinfra/bihash_template.h')
-rw-r--r-- | src/vppinfra/bihash_template.h | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h index 2a5c5861d88..8f5879b4634 100644 --- a/src/vppinfra/bihash_template.h +++ b/src/vppinfra/bihash_template.h @@ -99,7 +99,6 @@ typedef struct STATIC_ASSERT_SIZEOF (BVT (clib_bihash_bucket), sizeof (u64)); -/* *INDENT-OFF* */ typedef CLIB_PACKED (struct { /* * Backing store allocation. Since bihash manages its own @@ -118,7 +117,6 @@ typedef CLIB_PACKED (struct { volatile u32 ready; u64 pad[1]; }) BVT (clib_bihash_shared_header); -/* *INDENT-ON* */ STATIC_ASSERT_SIZEOF (BVT (clib_bihash_shared_header), 8 * sizeof (u64)); @@ -282,9 +280,7 @@ static inline void BV (clib_bihash_alloc_unlock) (BVT (clib_bihash) * h) static inline void BV (clib_bihash_lock_bucket) (BVT (clib_bihash_bucket) * b) { - /* *INDENT-OFF* */ BVT (clib_bihash_bucket) mask = { .lock = 1 }; - /* *INDENT-ON* */ u64 old; try_again: @@ -356,12 +352,19 @@ void BV (clib_bihash_free) (BVT (clib_bihash) * h); int BV (clib_bihash_add_del) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * add_v, int is_add); + +int BV (clib_bihash_add_del_with_hash) (BVT (clib_bihash) * h, + BVT (clib_bihash_kv) * add_v, u64 hash, + int is_add); int BV (clib_bihash_add_or_overwrite_stale) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * add_v, int (*is_stale_cb) (BVT (clib_bihash_kv) *, void *), void *arg); +int BV (clib_bihash_add_with_overwrite_cb) ( + BVT (clib_bihash) * h, BVT (clib_bihash_kv) * add_v, + void (*overwrite_cb) (BVT (clib_bihash_kv) *, void *), void *arg); int BV (clib_bihash_search) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * search_v, BVT (clib_bihash_kv) * return_v); @@ -403,16 +406,15 @@ BV (clib_bihash_get_bucket) (BVT (clib_bihash) * h, u64 hash) static inline int BV (clib_bihash_search_inline_with_hash) (BVT (clib_bihash) * h, u64 hash, BVT (clib_bihash_kv) * key_result) { + BVT (clib_bihash_kv) rv; BVT (clib_bihash_value) * v; BVT (clib_bihash_bucket) * b; int i, limit; - /* *INDENT-OFF* */ static const BVT (clib_bihash_bucket) mask = { .linear_search = 1, .log2_pages = -1 }; - /* *INDENT-ON* */ #if BIHASH_LAZY_INSTANTIATE if (PREDICT_FALSE (h->instantiated == 0)) @@ -448,7 +450,10 @@ static inline int BV (clib_bihash_search_inline_with_hash) { if (BV (clib_bihash_key_compare) (v->kvp[i].key, key_result->key)) { - *key_result = v->kvp[i]; + rv = v->kvp[i]; + if (BV (clib_bihash_is_free) (&rv)) + return -1; + *key_result = rv; return 0; } } @@ -502,16 +507,15 @@ static inline int BV (clib_bihash_search_inline_2_with_hash) (BVT (clib_bihash) * h, u64 hash, BVT (clib_bihash_kv) * search_key, BVT (clib_bihash_kv) * valuep) { + BVT (clib_bihash_kv) rv; BVT (clib_bihash_value) * v; BVT (clib_bihash_bucket) * b; int i, limit; -/* *INDENT-OFF* */ static const BVT (clib_bihash_bucket) mask = { .linear_search = 1, .log2_pages = -1 }; -/* *INDENT-ON* */ ASSERT (valuep); @@ -549,7 +553,10 @@ static inline int BV (clib_bihash_search_inline_2_with_hash) { if (BV (clib_bihash_key_compare) (v->kvp[i].key, search_key->key)) { - *valuep = v->kvp[i]; + rv = v->kvp[i]; + if (BV (clib_bihash_is_free) (&rv)) + return -1; + *valuep = rv; return 0; } } |