From: Umang Sharma (umasharm) Date: Wed, 30 Jul 2025 20:13:57 +0000 (+0000) Subject: Pull request #4837: helpers: ring uses atomic X-Git-Tag: 3.9.3.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b3a83112c17ca854c93a15cdf50adef2a40641e;p=thirdparty%2Fsnort3.git Pull request #4837: helpers: ring uses atomic Merge in SNORT/snort3 from ~UMASHARM/snort3:ring_atomic to master Squashed commit of the following: commit 8fb651860ecc4da16bb2aaed5728cc64bbd91573 Author: Umang Sharma Date: Fri Jul 25 02:56:46 2025 -0400 helpers: RingLogic framework updated to use atomic than volatile --- diff --git a/src/helpers/ring_logic.h b/src/helpers/ring_logic.h index 3453e28d9..c2aef8fe1 100644 --- a/src/helpers/ring_logic.h +++ b/src/helpers/ring_logic.h @@ -20,6 +20,7 @@ #ifndef RING_LOGIC_H #define RING_LOGIC_H +#include // Logic for simple ring implementation class RingLogic @@ -45,16 +46,12 @@ private: private: int sz; - volatile int rx; - volatile int wx; + std::atomic rx; + std::atomic wx; }; -inline RingLogic::RingLogic(int size) -{ - sz = size; - rx = 0; - wx = 1; -} +inline RingLogic::RingLogic(int size) : sz(size), rx(0), wx(1) +{} inline int RingLogic::read() { @@ -65,7 +62,7 @@ inline int RingLogic::read() inline int RingLogic::write() { int nx = next(wx); - return ( nx == rx ) ? -1 : wx; + return ( nx == rx.load() ) ? -1 : wx.load(); } inline bool RingLogic::push()