From ce7c3c752b115fd00c909f0febc518766a460875 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Thu, 13 Oct 2022 19:48:43 +0200 Subject: [PATCH] Handle overflow write --- LibSnugLog/include/disruptor.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LibSnugLog/include/disruptor.h b/LibSnugLog/include/disruptor.h index 32c0588..1d207b3 100644 --- a/LibSnugLog/include/disruptor.h +++ b/LibSnugLog/include/disruptor.h @@ -97,7 +97,7 @@ public: // Check if we jumped the fence if(fence_v <= new_offset && fence_v > old_offset) { - return std::nullopt; + goto handle_fence; } // Check if we jumped the fence while overflowing @@ -108,9 +108,25 @@ public: new_offset %= max_offset; } if(fence_v <= new_offset) { + goto handle_fence; + } + } + + goto handle_fence_end; + handle_fence: + if constexpr (OverflowStrategy::on_overflow == overflow_response_t::must_wait) { + return std::nullopt; + } else if constexpr (OverflowStrategy::on_overflow == overflow_response_t::must_overflow) { + if(!fence.compare_exchange_weak(fence_v, new_offset, std::memory_order_release, std::memory_order_relaxed)) { return std::nullopt; } + } else { + static_assert( + OverflowStrategy::on_overflow == overflow_response_t::must_wait + || OverflowStrategy::on_overflow == overflow_response_t::must_overflow + ); } + handle_fence_end: if(!lead.compare_exchange_weak(old_offset, new_offset, std::memory_order_acquire, std::memory_order_relaxed)) { return std::nullopt;