rx-placement: Add API call for interface rx-placement
[vpp.git] / src / vppinfra / bihash_template.h
index 6303992..4ff7e1b 100644 (file)
@@ -27,6 +27,7 @@
 #include <vppinfra/format.h>
 #include <vppinfra/pool.h>
 #include <vppinfra/cache.h>
+#include <vppinfra/lock.h>
 
 #ifndef BIHASH_TYPE
 #error BIHASH_TYPE not defined
@@ -83,9 +84,6 @@ typedef struct
   u32 log2_nbuckets;
   u8 *name;
 
-  u64 cache_hits;
-  u64 cache_misses;
-
     BVT (clib_bihash_value) ** freelists;
 
   /*
@@ -106,7 +104,7 @@ typedef struct
 static inline void BV (clib_bihash_alloc_lock) (BVT (clib_bihash) * h)
 {
   while (__atomic_test_and_set (h->alloc_lock, __ATOMIC_ACQUIRE))
-    ;
+    CLIB_PAUSE ();
 }
 
 static inline void BV (clib_bihash_alloc_unlock) (BVT (clib_bihash) * h)
@@ -123,6 +121,7 @@ static inline void BV (clib_bihash_lock_bucket) (BVT (clib_bihash_bucket) * b)
       locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
       unlocked_bucket.lock = 0;
       locked_bucket.lock = 1;
+      CLIB_PAUSE ();
     }
   while (__atomic_compare_exchange_n (&b->as_u64, &unlocked_bucket.as_u64,
                                      locked_bucket.as_u64, 1 /* weak */ ,
@@ -174,6 +173,12 @@ 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_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_search) (BVT (clib_bihash) * h,
                             BVT (clib_bihash_kv) * search_v,
                             BVT (clib_bihash_kv) * return_v);
@@ -203,7 +208,7 @@ static inline int BV (clib_bihash_search_inline_with_hash)
     {
       volatile BVT (clib_bihash_bucket) * bv = b;
       while (bv->lock)
-       ;
+       CLIB_PAUSE ();
     }
 
   hash >>= h->log2_nbuckets;
@@ -291,7 +296,7 @@ static inline int BV (clib_bihash_search_inline_2_with_hash)
     {
       volatile BVT (clib_bihash_bucket) * bv = b;
       while (bv->lock)
-       ;
+       CLIB_PAUSE ();
     }
 
   hash >>= h->log2_nbuckets;