diff --git a/emper/lib/adt/WsClQueue.hpp b/emper/lib/adt/WsClQueue.hpp index 881fff3745607d06aa240f2c3fca331438f1a4f1..ec90f9196eb9a047c4af193d471c9a95a6b7bd07 100644 --- a/emper/lib/adt/WsClQueue.hpp +++ b/emper/lib/adt/WsClQueue.hpp @@ -109,6 +109,11 @@ bool WsClQueue<_PAYLOAD, _CAPACITY>::popBottom(_PAYLOAD *item) { // bool res = top.compare_exchange_weak(localTop, localTop + 1, std::memory_order_release, std::memory_order_relaxed); bool res = top.compare_exchange_weak(localTop, localTop + 1); + // Either a popTop() removed the element ('res' is false) or we + // removed the element ('res' is true), but we need to increment + // the 'bottom' value, since the element bottom pointed at is now + // gone. N.B. bottom does point to the next free slot, the actual + // element we remove is bottom-1. bottom = localBottom + 1; return res; } diff --git a/emper/lib/adt/WsClV2Queue.hpp b/emper/lib/adt/WsClV2Queue.hpp index ebb4343b3168b1ac271d2582cefe6f6da514c198..102f8867570f48f724543f4f3ff26004556e70d1 100644 --- a/emper/lib/adt/WsClV2Queue.hpp +++ b/emper/lib/adt/WsClV2Queue.hpp @@ -100,7 +100,11 @@ bool WsClV2Queue<ITEM_TYPE, CAPACITY>::popBottom(ITEM_TYPE *item) { if (localBottom > localTop) return true; bool res = top.compare_exchange_weak(localTop, localTop + 1, std::memory_order_release, std::memory_order_relaxed); - // TODO: Why do we reset bottom here? + // Either a popTop() removed the element ('res' is false) or we + // removed the element ('res' is true), but we need to increment + // the 'bottom' value, since the element bottom pointed at is now + // gone. N.B. bottom does point to the next free slot, the actual + // element we remove is bottom-1. bottom = localBottom + 1; return res; }