Commit da6a6cde authored by Xavier Thompson's avatar Xavier Thompson

Invert top and bottom back in deque.hpp

parent e1a93b3f
......@@ -144,57 +144,57 @@ namespace typon
void push(T x) noexcept
{
u64 t = _top.load(relaxed);
u64 b = _bottom.load(acquire);
u64 bottom = _bottom.load(relaxed);
u64 top = _top.load(acquire);
Array * array = _array.load(relaxed);
if (t - b > array->capacity() - 1)
if (bottom - top > array->capacity() - 1)
{
array = array->grow(b, t);
array = array->grow(top, bottom);
_array.store(array);
}
array->put(t, x);
array->put(bottom, x);
std::atomic_thread_fence(release);
_top.store(t + 1, relaxed);
_bottom.store(bottom + 1, relaxed);
}
Optional<T> pop() noexcept
{
u64 t = _top.load(relaxed) - 1;
u64 bottom = _bottom.load(relaxed) - 1;
Array * array = _array.load(relaxed);
_top.store(t, relaxed);
_bottom.store(bottom, relaxed);
std::atomic_thread_fence(seq_cst);
u64 b = _bottom.load(relaxed);
u64 top = _top.load(relaxed);
Optional<T> x {};
if (b <= t)
if (top <= bottom)
{
x = array->get(t);
if (b == t)
x = array->get(bottom);
if (top == bottom)
{
if (!_bottom.compare_exchange_strong(b, b + 1, seq_cst, relaxed))
if (!_top.compare_exchange_strong(top, top + 1, seq_cst, relaxed))
{
x = {};
}
_top.store(t + 1, relaxed);
_bottom.store(bottom + 1, relaxed);
}
}
else
{
_top.store(t + 1, relaxed);
_bottom.store(bottom + 1, relaxed);
}
return x;
}
Optional<T> steal() noexcept
{
u64 b = _bottom.load(acquire);
u64 top = _top.load(acquire);
std::atomic_thread_fence(seq_cst);
u64 t = _top.load(acquire);
u64 bottom = _bottom.load(acquire);
Optional<T> x {};
if (b < t)
if (top < bottom)
{
Array * array = _array.load(consume);
x = array->get(b);
if (!_bottom.compare_exchange_strong(b, b + 1, seq_cst, relaxed))
x = array->get(top);
if (!_top.compare_exchange_strong(top, top + 1, seq_cst, relaxed))
{
return {Optional<T>::abort};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment