Mark MsgThread::cnt_sent_{in,out} as atomic to avoid a data race

This commit is contained in:
Tim Wojtulewicz 2021-08-09 10:39:56 -07:00
parent a2ab1b1484
commit 4dc20826fd
2 changed files with 9 additions and 5 deletions

View file

@ -202,7 +202,9 @@ Message::~Message()
MsgThread::MsgThread() : BasicThread(), queue_in(this, nullptr), queue_out(nullptr, this)
{
cnt_sent_in = cnt_sent_out = 0;
cnt_sent_in.store(0);
cnt_sent_out.store(0);
main_finished = false;
child_finished = false;
child_sent_finish = false;
@ -457,8 +459,8 @@ void MsgThread::Run()
void MsgThread::GetStats(Stats* stats)
{
stats->sent_in = cnt_sent_in;
stats->sent_out = cnt_sent_out;
stats->sent_in = cnt_sent_in.load();
stats->sent_out = cnt_sent_out.load();
stats->pending_in = queue_in.Size();
stats->pending_out = queue_out.Size();
queue_in.GetStats(&stats->queue_in_stats);

View file

@ -1,5 +1,7 @@
#pragma once
#include <atomic>
#include "zeek/DebugLogger.h"
#include "zeek/threading/BasicThread.h"
#include "zeek/threading/Queue.h"
@ -335,8 +337,8 @@ private:
Queue<BasicInputMessage *> queue_in;
Queue<BasicOutputMessage *> queue_out;
uint64_t cnt_sent_in; // Counts message sent to child.
uint64_t cnt_sent_out; // Counts message sent by child.
std::atomic<uint64_t> cnt_sent_in; // Counts message sent to child.
std::atomic<uint64_t> cnt_sent_out; // Counts message sent by child.
bool main_finished; // Main thread is finished, meaning child_finished propagated back through message queue.
bool child_finished; // Child thread is finished.