Skip to content

Commit

Permalink
[core] Made CRcvQueue::m_counter atomic to avoid data race.
Browse files Browse the repository at this point in the history
Used for setting the RcvQueue:: worker thread name for logging.
  • Loading branch information
maxsharabayko committed Jun 16, 2022
1 parent 6a489e1 commit c9e48bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ srt::CRcvQueue::~CRcvQueue()
}

#if ENABLE_LOGGING
int srt::CRcvQueue::m_counter = 0;
srt::sync::atomic<int> srt::CRcvQueue::m_counter(0);
#endif

void srt::CRcvQueue::init(int qsize, size_t payload, int version, int hsize, CChannel* cc, CTimer* t)
Expand All @@ -1200,8 +1200,8 @@ void srt::CRcvQueue::init(int qsize, size_t payload, int version, int hsize, CCh
m_pRendezvousQueue = new CRendezvousQueue;

#if ENABLE_LOGGING
++m_counter;
const std::string thrname = "SRT:RcvQ:w" + Sprint(m_counter);
const int cnt = ++m_counter;
const std::string thrname = "SRT:RcvQ:w" + Sprint(cnt);
#else
const std::string thrname = "SRT:RcvQ:w";
#endif
Expand Down
2 changes: 1 addition & 1 deletion srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class CRcvQueue

sync::atomic<bool> m_bClosing; // closing the worker
#if ENABLE_LOGGING
static int m_counter;
static srt::sync::atomic<int> m_counter; // A static counter to log RcvQueue worker thread number.
#endif

private:
Expand Down

0 comments on commit c9e48bd

Please sign in to comment.