From 08f44845ce828a243bacb18abd906aa26515dd87 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 26 Apr 2018 22:41:11 +0200 Subject: [PATCH] Fix issue for SPSC queue: computing the number of elements in the queue is not reliable enough as we can get more than than the size of the queue. --- m-buffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/m-buffer.h b/m-buffer.h index 596121cd..235d3f9b 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -664,7 +664,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ memory_order_relaxed); \ unsigned int w = atomic_load_explicit(&table->prodIdx, \ memory_order_acquire); \ - if (w-r == table->size) \ + if (w-r >= table->size) \ return false; \ unsigned int i = w & (table->size -1); \ if (!BUFFERI_POLICY_P((policy), BUFFER_PUSH_INIT_POP_MOVE)) { \ @@ -729,7 +729,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ static inline bool \ M_C(name, _full_p)(buffer_t v) \ { \ - return M_C(name, _size)(v) == v->size; \ + return M_C(name, _size)(v) >= v->size; \ } \ \ static inline void \