From 70a21cc8f08bbdbcdc3e6790ea5575ec732d3cca Mon Sep 17 00:00:00 2001 From: Coldwings Date: Thu, 26 Oct 2023 10:05:18 +0800 Subject: [PATCH] Fix lockfree queue size and full check (#203) 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; }