]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4837: helpers: ring uses atomic
authorUmang Sharma (umasharm) <umasharm@cisco.com>
Wed, 30 Jul 2025 20:13:57 +0000 (20:13 +0000)
committerChris Sherwin (chsherwi) <chsherwi@cisco.com>
Wed, 30 Jul 2025 20:13:57 +0000 (20:13 +0000)
Merge in SNORT/snort3 from ~UMASHARM/snort3:ring_atomic to master

Squashed commit of the following:

commit 8fb651860ecc4da16bb2aaed5728cc64bbd91573
Author: Umang Sharma <umasharm@cisco.com>
Date:   Fri Jul 25 02:56:46 2025 -0400

    helpers: RingLogic framework updated to use atomic than volatile

src/helpers/ring_logic.h

index 3453e28d9d3d82b3de123da2bfdd732e825f35c1..c2aef8fe10c4919ce40a2b606929ed17f384aebb 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef RING_LOGIC_H
 #define RING_LOGIC_H
 
+#include <atomic>
 // Logic for simple ring implementation
 
 class RingLogic
@@ -45,16 +46,12 @@ private:
 
 private:
     int sz;
-    volatile int rx;
-    volatile int wx;
+    std::atomic<int> rx;
+    std::atomic<int> 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()