diff options
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/bihash_doc.h | 14 | ||||
-rw-r--r-- | src/vppinfra/bihash_template.c | 7 | ||||
-rw-r--r-- | src/vppinfra/bihash_template.h | 10 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/vppinfra/bihash_doc.h b/src/vppinfra/bihash_doc.h index a7e70e9695c..da8c832f160 100644 --- a/src/vppinfra/bihash_doc.h +++ b/src/vppinfra/bihash_doc.h @@ -165,17 +165,25 @@ void clib_bihash_prefetch_data (clib_bihash * h, u64 hash); int clib_bihash_search_inline_2 (clib_bihash * h, clib_bihash_kv * search_key, clib_bihash_kv * valuep); +/* Calback function for walking a bihash table + * + * @param kv - KV pair visited + * @param ctx - Context passed to the walk + * @return BIHASH_WALK_CONTINUE to continue BIHASH_WALK_STOP to stop + */ +typedef int (*clib_bihash_foreach_key_value_pair_cb) (clib_bihash_kv * kv, + void *ctx); + /** Visit active (key,value) pairs in a bi-hash table @param h - the bi-hash table to search @param callback - function to call with each active (key,value) pair @param arg - arbitrary second argument passed to the callback function First argument is the (key,value) pair to visit - @note Trying to supply a proper function prototype for the - callback function appears to be a fool's errand. */ void clib_bihash_foreach_key_value_pair (clib_bihash * h, - void *callback, void *arg); + clib_bihash_foreach_key_value_pair_cb + * callback, void *arg); /* * fd.io coding-style-patch-verification: ON diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c index 97c4cd08eb1..b090041ad29 100644 --- a/src/vppinfra/bihash_template.c +++ b/src/vppinfra/bihash_template.c @@ -906,12 +906,12 @@ u8 *BV (format_bihash) (u8 * s, va_list * args) } void BV (clib_bihash_foreach_key_value_pair) - (BVT (clib_bihash) * h, void *callback, void *arg) + (BVT (clib_bihash) * h, + BV (clib_bihash_foreach_key_value_pair_cb) cb, void *arg) { int i, j, k; BVT (clib_bihash_bucket) * b; BVT (clib_bihash_value) * v; - void (*fp) (BVT (clib_bihash_kv) *, void *) = callback; if (PREDICT_FALSE (alloc_arena (h) == 0)) return; @@ -930,7 +930,8 @@ void BV (clib_bihash_foreach_key_value_pair) if (BV (clib_bihash_is_free) (&v->kvp[k])) continue; - (*fp) (&v->kvp[k], arg); + if (BIHASH_WALK_STOP == cb (&v->kvp[k], arg)) + return; /* * In case the callback deletes the last entry in the bucket... */ diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h index ebd70c03371..f11e6d506ab 100644 --- a/src/vppinfra/bihash_template.h +++ b/src/vppinfra/bihash_template.h @@ -328,8 +328,16 @@ int BV (clib_bihash_search) (BVT (clib_bihash) * h, BVT (clib_bihash_kv) * search_v, BVT (clib_bihash_kv) * return_v); +#define BIHASH_WALK_STOP 0 +#define BIHASH_WALK_CONTINUE 1 + +typedef + int (*BV (clib_bihash_foreach_key_value_pair_cb)) (BVT (clib_bihash_kv) *, + void *); void BV (clib_bihash_foreach_key_value_pair) (BVT (clib_bihash) * h, - void *callback, void *arg); + BV + (clib_bihash_foreach_key_value_pair_cb) + cb, void *arg); void *clib_all_bihash_set_heap (void); void clib_bihash_copied (void *dst, void *src); |