Add atomic to check for concurrency issues

This commit is contained in:
Alfredo Cardigliano 2024-08-09 18:18:06 +02:00
parent 112bf29b9e
commit 0ba4c2f44b
4 changed files with 9 additions and 10 deletions

View file

@ -250,15 +250,14 @@ protected:
hostAlertsDequeueLoopCreated;
bool has_too_many_hosts, has_too_many_flows, mtuWarningShown;
bool flow_dump_disabled_by_user, flow_dump_disabled_by_backend;
u_int32_t ifSpeed, numL2Devices, totalNumHosts,
numTotalRxOnlyHosts /* subset of numTotalRxOnlyHosts that have received
u_int32_t ifSpeed, scalingFactor;
u_int32_t numL2Devices;
std::atomic<u_int64_t> totalNumHosts;
std::atomic<u_int64_t> numTotalRxOnlyHosts; /* subset of numTotalRxOnlyHosts that have received
but never sent any traffic */
,
numLocalHosts,
numLocalRxOnlyHosts /* subset of numLocalHosts that have received but
std::atomic<u_int64_t> numLocalHosts;
std::atomic<u_int64_t> numLocalRxOnlyHosts; /* subset of numLocalHosts that have received but
never sent any traffic */
,
scalingFactor;
/* Those will hold counters at checkpoints */
u_int64_t checkpointPktCount, checkpointBytesCount, checkpointPktDropCount,
checkpointDroppedAlertsCount;

View file

@ -438,7 +438,7 @@ void HostStats::incStats(time_t when, u_int8_t l4_proto, u_int ndpi_proto,
sent_bytes);
if (host->isRxOnlyHost() && !isReceiveOnly()) /* no longer RX-only */
host->toggleRxOnlyHost(false);
host->toggleRxOnlyHost(false);
}
#ifdef NTOPNG_PRO

View file

@ -11140,7 +11140,7 @@ void NetworkInterface::decNumHosts(bool local, bool rxOnlyHost) {
if(rxOnlyHost) {
/* Decrease total number of RX only hosts */
if (!numTotalRxOnlyHosts) {
ntop->getTrace()->traceEvent(TRACE_WARNING, "Internal Error (%d) on interface %s: Counter overflow", 3, ifname); // <---
ntop->getTrace()->traceEvent(TRACE_WARNING, "Internal Error (%d) on interface %s: Counter overflow", 3, ifname);
} else {
numTotalRxOnlyHosts--;
}

View file

@ -51,7 +51,7 @@ RemoteHost::RemoteHost(NetworkInterface *_iface, int32_t _iface_idx,
RemoteHost::~RemoteHost() {
/* Decrease number of active hosts */
if(isUnicastHost())
iface->decNumHosts(isLocalHost(), isRxOnlyHost());
iface->decNumHosts(isLocalHost(), is_rx_only);
}
/* *************************************** */