From 4c40e98a55757de2faf5fb73611de528d7601852 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Wed, 25 Oct 2023 17:30:10 +0800 Subject: [PATCH] Fix lockfree queue size and full check Signed-off-by: Coldwings --- common/lockfree_queue.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/lockfree_queue.h b/common/lockfree_queue.h index eb19262f..8bdcaac3 100644 --- a/common/lockfree_queue.h +++ b/common/lockfree_queue.h @@ -58,6 +58,9 @@ struct Capacity_2expN<0> { template <> struct Capacity_2expN<1> : public Capacity_2expN<0> {}; +template <> +struct Capacity_2expN<2> : public Capacity_2expN<0> {}; + struct PauseBase {}; struct CPUPause : PauseBase { @@ -136,7 +139,7 @@ class LockfreeRingQueueBase { bool check_empty(size_t h, size_t t) const { return h == t; } bool check_full(size_t h, size_t t) const { - return check_mask_equal(h, t + 1); + return h != t && check_mask_equal(h, t); } size_t idx(size_t x) const { return x & mask; }