if (ftd == NULL)
return TM_ECODE_FAILED;
- ftd->instance = SC_ATOMIC_ADD(detect_loader_cnt, 1) - 1; /* id's start at 0 */
+ ftd->instance = SC_ATOMIC_ADD(detect_loader_cnt, 1); /* id's start at 0 */
SCLogDebug("detect loader instance %u", ftd->instance);
/* pass thread data back to caller */
/* set the min and max value used for hash row walking
* each thread has it's own section of the flow hash */
uint32_t range = flow_config.hash_size / flowmgr_number;
- if (ftd->instance == 1)
+ if (ftd->instance == 0)
ftd->max = range;
- else if (ftd->instance == flowmgr_number) {
+ else if ((ftd->instance + 1) == flowmgr_number) {
ftd->min = (range * (ftd->instance - 1));
ftd->max = flow_config.hash_size;
} else {
PcapLogDataDeinit, NULL);
PcapLogProfileSetup();
SC_ATOMIC_INIT(thread_cnt);
+ SC_ATOMIC_SET(thread_cnt, 1); /* first id is 1 */
return;
}
LogTlsStoreLogThreadDeinit, LogTlsStoreLogExitPrintStats);
SC_ATOMIC_INIT(cert_id);
+ SC_ATOMIC_SET(cert_id, 1);
SCLogDebug("registered");
}
if (fgets(line, (int)sizeof(line), fp) != NULL) {
if (sscanf(line, "%10u", &id) == 1) {
SCLogInfo("id %u", id);
- (void) SC_ATOMIC_CAS(&g_file_store_id, 0, id);
+ SC_ATOMIC_SET(g_file_store_id, id);
}
}
fclose(fp);
{
char line[16] = "";
- if (SC_ATOMIC_GET(g_file_store_id) == 0) {
+ if (SC_ATOMIC_GET(g_file_store_id) == 1) {
SCReturn;
}
OutputFiledataLogThreadDeinit, OutputFiledataLogExitPrintStats,
OutputFiledataLog, OutputFiledataLoggerGetActiveCount);
SC_ATOMIC_INIT(g_file_store_id);
+ SC_ATOMIC_SET(g_file_store_id, 1);
}
void OutputFiledataShutdown(void)
{
AFPIfaceConfig *pfp = (AFPIfaceConfig *)conf;
/* Pcap config is used only once but cost of this low. */
- if (SC_ATOMIC_SUB(pfp->ref, 1) == 0) {
+ if (SC_ATOMIC_SUB(pfp->ref, 1) == 1) {
SCFree(pfp);
}
}
{
NetmapIfaceConfig *pfp = (NetmapIfaceConfig *)conf;
/* config is used only once but cost of this low. */
- if (SC_ATOMIC_SUB(pfp->ref, 1) == 0) {
+ if (SC_ATOMIC_SUB(pfp->ref, 1) == 1) {
SCFree(pfp);
}
}
{
PcapIfaceConfig *pfp = (PcapIfaceConfig *)conf;
/* Pcap config is used only once but cost of this low. */
- if (SC_ATOMIC_SUB(pfp->ref, 1) == 0) {
+ if (SC_ATOMIC_SUB(pfp->ref, 1) == 1) {
SCFree(pfp);
}
}
static void PfringDerefConfig(void *conf)
{
PfringIfaceConfig *pfp = (PfringIfaceConfig *)conf;
- if (SC_ATOMIC_SUB(pfp->ref, 1) == 0) {
+ if (SC_ATOMIC_SUB(pfp->ref, 1) == 1) {
if (pfp->bpf_filter) {
SCFree(pfp->bpf_filter);
}
if (peerslist.turn == 0)
return;
- if (SC_ATOMIC_ADD(peerslist.reached, 1) == peerslist.turn) {
+ if ((SC_ATOMIC_ADD(peerslist.reached, 1) + 1) == peerslist.turn) {
SCLogInfo("All AFP capture threads are running.");
(void)SC_ATOMIC_SET(peerslist.reached, 0);
/* Set turn to 0 to skip syncrhonization when ReceiveAFPLoop is
if (peer == NULL)
return 1;
- if (SC_ATOMIC_SUB(peer->sock_usage, 1) == 0) {
+ if (SC_ATOMIC_SUB(peer->sock_usage, 1) == 1) {
if (SC_ATOMIC_GET(peer->state) == AFP_STATE_DOWN) {
SCLogInfo("Cleaning socket connected to '%s'", peer->iface);
close(SC_ATOMIC_GET(peer->socket));
#endif
if (ptv->socket != -1) {
/* we need to wait for all packets to return data */
- if (SC_ATOMIC_SUB(ptv->mpeer->sock_usage, 1) == 0) {
+ if (SC_ATOMIC_SUB(ptv->mpeer->sock_usage, 1) == 1) {
SCLogDebug("Cleaning socket connected to '%s'", ptv->iface);
munmap(ptv->ring_buf, ptv->ring_buflen);
close(ptv->socket);
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2020 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* \param val the value to add to the variable
*/
#define SC_ATOMIC_ADD(name, val) \
- SCAtomicAddAndFetch(&(name ## _sc_atomic__), (val))
+ SCAtomicFetchAndAdd(&(name ## _sc_atomic__), (val))
/**
* \brief sub a value from our atomic variable
* \param val the value to sub from the variable
*/
#define SC_ATOMIC_SUB(name, val) \
- SCAtomicSubAndFetch(&(name ## _sc_atomic__), (val))
+ SCAtomicFetchAndSub(&(name ## _sc_atomic__), (val))
/**
* \brief Bitwise OR a value to our atomic variable