summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/bihash_template.h20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h
index b8e0a239013..50b4af65710 100644
--- a/src/vppinfra/bihash_template.h
+++ b/src/vppinfra/bihash_template.h
@@ -260,21 +260,19 @@ 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)
{
- BVT (clib_bihash_bucket) unlocked_bucket, locked_bucket;
+ /* *INDENT-OFF* */
+ BVT (clib_bihash_bucket) mask = { .lock = 1 };
+ /* *INDENT-ON* */
+ u64 old;
- locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
- unlocked_bucket.lock = 0;
- locked_bucket.lock = 1;
+try_again:
+ old = clib_atomic_fetch_or (&b->as_u64, mask.as_u64);
- while (__atomic_compare_exchange_n (&b->as_u64, &unlocked_bucket.as_u64,
- locked_bucket.as_u64, 1 /* weak */ ,
- __ATOMIC_ACQUIRE,
- __ATOMIC_ACQUIRE) == 0)
+ if (PREDICT_FALSE (old & mask.as_u64))
{
+ /* somebody else flipped the bit, try again */
CLIB_PAUSE ();
- locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
- unlocked_bucket.lock = 0;
- locked_bucket.lock = 1;
+ goto try_again;
}
}