Fix api test_client.c compilation
[vpp.git] / src / vppinfra / bihash_template.c
index e3a5759..56c410b 100644 (file)
@@ -35,6 +35,7 @@ void BV (clib_bihash_init)
   vec_validate_aligned (h->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
   h->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
                                           CLIB_CACHE_LINE_BYTES);
+  h->writer_lock[0] = 0;
 
   for (i = 0; i < nbuckets; i++)
     BV (clib_bihash_reset_cache) (h->buckets + i);
@@ -135,8 +136,9 @@ BV (make_working_copy) (BVT (clib_bihash) * h, BVT (clib_bihash_bucket) * b)
 
   clib_mem_set_heap (oldheap);
 
-  /* Turn off the cache */
-  BV (clib_bihash_cache_enable_disable) (b, 0);
+  /* Lock the bucket... */
+  while (BV (clib_bihash_lock_bucket) (b) == 0)
+    ;
 
   v = BV (clib_bihash_get_value) (h, b->offset);
 
@@ -416,7 +418,7 @@ expand_ok:
 
 unlock:
   BV (clib_bihash_reset_cache) (b);
-  BV (clib_bihash_cache_enable_disable) (b, 1 /* enable */ );
+  BV (clib_bihash_unlock_bucket) (b);
   CLIB_MEMORY_BARRIER ();
   h->writer_lock[0] = 0;
   return rv;
@@ -429,7 +431,9 @@ int BV (clib_bihash_search)
   u64 hash;
   u32 bucket_index;
   BVT (clib_bihash_value) * v;
+#if BIHASH_KVP_CACHE_SIZE > 0
   BVT (clib_bihash_kv) * kvp;
+#endif
   BVT (clib_bihash_bucket) * b;
   int i, limit;
 
@@ -443,8 +447,9 @@ int BV (clib_bihash_search)
   if (b->offset == 0)
     return -1;
 
+#if BIHASH_KVP_CACHE_SIZE > 0
   /* Check the cache, if currently enabled */
-  if (PREDICT_TRUE (b->cache_lru & (1 << 15)))
+  if (PREDICT_TRUE ((b->cache_lru & (1 << 15)) == 0))
     {
       limit = BIHASH_KVP_CACHE_SIZE;
       kvp = b->cache;
@@ -458,6 +463,7 @@ int BV (clib_bihash_search)
            }
        }
     }
+#endif
 
   hash >>= h->log2_nbuckets;
 
@@ -471,20 +477,22 @@ int BV (clib_bihash_search)
     {
       if (BV (clib_bihash_key_compare) (v->kvp[i].key, search_key->key))
        {
-         u8 cache_slot;
          *valuep = v->kvp[i];
 
+#if BIHASH_KVP_CACHE_SIZE > 0
+         u8 cache_slot;
          /* Shut off the cache */
-         BV (clib_bihash_cache_enable_disable) (b, 0);
-         CLIB_MEMORY_BARRIER ();
-
-         cache_slot = BV (clib_bihash_get_lru) (b);
-         b->cache[cache_slot] = v->kvp[i];
-         BV (clib_bihash_update_lru) (b, cache_slot);
+         if (BV (clib_bihash_lock_bucket) (b))
+           {
+             cache_slot = BV (clib_bihash_get_lru) (b);
+             b->cache[cache_slot] = v->kvp[i];
+             BV (clib_bihash_update_lru) (b, cache_slot);
 
-         /* Reenable the cache */
-         BV (clib_bihash_cache_enable_disable) (b, 1);
-         h->cache_misses++;
+             /* Reenable the cache */
+             BV (clib_bihash_unlock_bucket) (b);
+             h->cache_misses++;
+           }
+#endif
          return 0;
        }
     }
@@ -493,6 +501,7 @@ int BV (clib_bihash_search)
 
 u8 *BV (format_bihash_lru) (u8 * s, va_list * args)
 {
+#if BIHASH_KVP_SIZE > 0
   int i;
   BVT (clib_bihash_bucket) * b = va_arg (*args, BVT (clib_bihash_bucket) *);
   u16 cache_lru = b->cache_lru;
@@ -501,13 +510,19 @@ u8 *BV (format_bihash_lru) (u8 * s, va_list * args)
 
   for (i = 0; i < BIHASH_KVP_CACHE_SIZE; i++)
     s = format (s, "[%d] ", ((cache_lru >> (3 * i)) & 7));
+
   return (s);
+#else
+  return format (s, "cache not configured");
+#endif
 }
 
 void
 BV (clib_bihash_update_lru_not_inline) (BVT (clib_bihash_bucket) * b, u8 slot)
 {
+#if BIHASH_KVP_SIZE > 0
   BV (clib_bihash_update_lru) (b, slot);
+#endif
 }
 
 u8 *BV (format_bihash) (u8 * s, va_list * args)