]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
atomics: add SC_ATOMIC_INITPTR macro
authorVictor Julien <victor@inliniac.net>
Sun, 12 Apr 2020 09:09:34 +0000 (11:09 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 16 Apr 2020 12:37:34 +0000 (14:37 +0200)
Until now both atomic ints and pointers were initialized by SC_ATOMIC_INIT
by setting them to 0. However, C11's atomic pointer type cannot be
initialized this way w/o causing compiler warnings.

As a preparation to supporting C11's atomics, this patch introduces a
new macro to initialize atomic pointers and updates the relevant callers
to use it.

src/flow-manager.c
src/flow-worker.c
src/tm-threads.c
src/util-atomic.c
src/util-atomic.h
src/util-var-name.c

index 6aecc9c8b3af92b10862121ec995c821da3c6d0c..150f30144e2a34aa21344894f054ad7c40a6f06e 100644 (file)
@@ -1138,7 +1138,7 @@ void TmModuleFlowManagerRegister (void)
     SCLogDebug("%s registered", tmm_modules[TMM_FLOWMANAGER].name);
 
     SC_ATOMIC_INIT(flowmgr_cnt);
-    SC_ATOMIC_INIT(flow_timeouts);
+    SC_ATOMIC_INITPTR(flow_timeouts);
 }
 
 void TmModuleFlowRecyclerRegister (void)
index c65483d71566147fcad5b87c33efb4cbf5cba5bd..579d3858f1d6f6a8cafab30e95b5252672f84944 100644 (file)
@@ -102,7 +102,7 @@ static TmEcode FlowWorkerThreadInit(ThreadVars *tv, const void *initdata, void *
     if (fw == NULL)
         return TM_ECODE_FAILED;
 
-    SC_ATOMIC_INIT(fw->detect_thread);
+    SC_ATOMIC_INITPTR(fw->detect_thread);
     SC_ATOMIC_SET(fw->detect_thread, NULL);
 
     fw->local_bypass_pkts = StatsRegisterCounter("flow_bypassed.local_pkts", tv);
index b8e14e12966a3a8a625721ba5be432aa11c8af71..b049b7ed6544414cbf42b0eb894ee60fc9be4e05 100644 (file)
@@ -626,7 +626,7 @@ void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
     if (unlikely(slot == NULL))
         return;
     memset(slot, 0, sizeof(TmSlot));
-    SC_ATOMIC_INIT(slot->slot_data);
+    SC_ATOMIC_INITPTR(slot->slot_data);
     slot->SlotThreadInit = tm->ThreadInit;
     slot->slot_initdata = data;
     if (tm->Func) {
index 569f4c0a344f0fddcb546a0d42ef1fb4d3bb822c..11aa51afd02baa0683535c587857d3dfee9e9cd2 100644 (file)
@@ -35,7 +35,8 @@ static int SCAtomicTest01(void)
     int b = 20;
     int *temp_int = NULL;
 
-    SC_ATOMIC_DECL_AND_INIT(void *, temp);
+    SC_ATOMIC_DECLARE(void *, temp);
+    SC_ATOMIC_INITPTR(temp);
 
     temp_int = SC_ATOMIC_GET(temp);
     if (temp_int != NULL)
index 85d0a02935440e624d63b1eb1c34ad4c50e2548b..410c1a43341b9bfcb33e4ebfc0605199d7f3099e 100644 (file)
 #define SC_ATOMIC_INIT(name) \
     (name ## _sc_atomic__) = 0
 
+#define SC_ATOMIC_INITPTR(name) \
+    (name ## _sc_atomic__) = NULL
+
 /**
  *  \brief wrapper for reinitializing an atomic variable.
  **/
index 3af35dc51e8ead442296ecd67d8a19deff57afae..3cc1231026a7073fd980ec6545b10552daeb37d9 100644 (file)
@@ -249,7 +249,7 @@ int VarNameStoreSetupStaging(uint32_t de_ctx_version)
     SCMutexLock(&g_varnamestore_staging_m);
 
     if (!initialized) {
-        SC_ATOMIC_INIT(g_varnamestore_current);
+        SC_ATOMIC_INITPTR(g_varnamestore_current);
         initialized = 1;
     }