From a31ded07977e2229ceec22b326b4b82cb3802851 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:30:27 +0100 Subject: [PATCH] Tentative atomic_queue patch --- src/external/atomic_queue/atomic_queue.h | 33 +++++++++++------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/external/atomic_queue/atomic_queue.h b/src/external/atomic_queue/atomic_queue.h index 19fdb40d..bcbd29a9 100644 --- a/src/external/atomic_queue/atomic_queue.h +++ b/src/external/atomic_queue/atomic_queue.h @@ -95,27 +95,24 @@ constexpr T& map(T* elements, unsigned index) noexcept { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +template +constexpr T decrement(T x) { return x - 1; } +template +constexpr T increment(T x) { return x + 1; } +template +constexpr T or_equal(T x, unsigned u) { return (x | x >> u); } +template +constexpr T or_equal(T x, unsigned u, Args... rest) +{ + return or_equal(or_equal(x, u), rest...); +} + constexpr uint32_t round_up_to_power_of_2(uint32_t a) noexcept { - --a; - a |= a >> 1; - a |= a >> 2; - a |= a >> 4; - a |= a >> 8; - a |= a >> 16; - ++a; - return a; + return increment(or_equal(decrement(a), 1, 2, 4, 8, 16)); } constexpr uint64_t round_up_to_power_of_2(uint64_t a) noexcept { - --a; - a |= a >> 1; - a |= a >> 2; - a |= a >> 4; - a |= a >> 8; - a |= a >> 16; - a |= a >> 32; - ++a; - return a; + return increment(or_equal(decrement(a), 1, 2, 4, 8, 16, 32)); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -304,7 +301,7 @@ public: static_cast(*this).do_push(std::forward(element), head); } - auto pop() noexcept { + Derived& pop() noexcept { unsigned tail; if(Derived::spsc_) { tail = tail_.load(X);