vppinfra: fix RC in bihash instantiation 28/28428/2
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Mon, 17 Aug 2020 12:14:56 +0000 (14:14 +0200)
committerNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Mon, 17 Aug 2020 14:33:50 +0000 (16:33 +0200)
There can be a race condition in the case
a thread tries to do a bihash_search while
another instantiates the bihash.

Type: fix

Change-Id: Ic61b590763beb409e112957c43a5a66cd10afb28
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vppinfra/bihash_template.c
src/vppinfra/bihash_template.h

index 02d84ab..aac66cb 100644 (file)
@@ -893,7 +893,7 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
   s = format (s, "Hash table %s\n", h->name ? h->name : (u8 *) "(unnamed)");
 
 #if BIHASH_LAZY_INSTANTIATE
-  if (PREDICT_FALSE (alloc_arena (h) == 0))
+  if (PREDICT_FALSE (h->instantiated == 0))
     return format (s, "[empty, uninitialized]");
 #endif
 
@@ -994,7 +994,7 @@ void BV (clib_bihash_foreach_key_value_pair)
 
 
 #if BIHASH_LAZY_INSTANTIATE
-  if (PREDICT_FALSE (alloc_arena (h) == 0))
+  if (PREDICT_FALSE (h->instantiated == 0))
     return;
 #endif
 
index 07adeb8..85c5d65 100644 (file)
@@ -388,7 +388,7 @@ static inline int BV (clib_bihash_search_inline_with_hash)
   /* *INDENT-ON* */
 
 #if BIHASH_LAZY_INSTANTIATE
-  if (PREDICT_FALSE (alloc_arena (h) == 0))
+  if (PREDICT_FALSE (h->instantiated == 0))
     return -1;
 #endif
 
@@ -453,7 +453,7 @@ static inline void BV (clib_bihash_prefetch_data)
   BVT (clib_bihash_bucket) * b;
 
 #if BIHASH_LAZY_INSTANTIATE
-  if (PREDICT_FALSE (alloc_arena (h) == 0))
+  if (PREDICT_FALSE (h->instantiated == 0))
     return;
 #endif
 
@@ -489,7 +489,7 @@ static inline int BV (clib_bihash_search_inline_2_with_hash)
   ASSERT (valuep);
 
 #if BIHASH_LAZY_INSTANTIATE
-  if (PREDICT_FALSE (alloc_arena (h) == 0))
+  if (PREDICT_FALSE (h->instantiated == 0))
     return -1;
 #endif