atomics: add SC_ATOMIC_INITPTR macro

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.
pull/4832/head
Victor Julien 5 years ago
parent 531ff3ddec
commit c83a607b6a

@ -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)

@ -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);

@ -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) {

@ -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)

@ -172,6 +172,9 @@
#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.
**/

@ -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;
}

Loading…
Cancel
Save