Merge pull request #446 from Lastique/feature/fix_cxx20_volatile_ops

Remove operations on volatile variables
This commit is contained in:
Scott Godin
2025-11-10 15:12:16 -05:00
committed by GitHub
3 changed files with 16 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
#include "rutil/Socket.hxx"
#include "rutil/ResipAssert.h"
#include <atomic>
#include <chrono>
#include <iomanip>
#include <iostream>
@@ -54,7 +55,7 @@ unsigned int Log::MaxLineCount = RESIP_LOG_MAX_LINE_COUNT_DEFAULT; // no limit b
unsigned int Log::MaxByteCount = RESIP_LOG_MAX_BYTE_COUNT_DEFAULT; // no limit by default
bool Log::KeepAllLogFiles = false; // do not keep all log files by default
volatile short Log::touchCount = 0;
std::atomic<unsigned int> Log::touchCount{0};
/// DEPRECATED! Left for backward compatibility - use localLoggers instead
@@ -823,7 +824,7 @@ Log::getThreadSetting()
{
return 0;
}
if (Log::touchCount > 0)
if (Log::touchCount.load(std::memory_order_relaxed) > 0)
{
Lock lock(_mutex);
ThreadIf::Id thread = ThreadIf::selfId();
@@ -833,8 +834,8 @@ Log::getThreadSetting()
{
setting->mLevel = res->second.first.mLevel;
res->second.second = false;
touchCount--;
// cerr << "**Log::getThreadSetting:touchCount: " << Log::touchCount << "**" << endl;
touchCount.fetch_sub(1, std::memory_order_relaxed);
// cerr << "**Log::getThreadSetting:touchCount: " << Log::touchCount.load(std::memory_order_relaxed) << "**" << endl;
//cerr << "touchcount decremented" << endl;
}
@@ -870,7 +871,7 @@ Log::setThreadSetting(ThreadSetting info)
{
if (Log::mThreadToLevel[thread].second == true)
{
touchCount--;
touchCount.fetch_sub(1, std::memory_order_relaxed);
}
}
Log::mThreadToLevel[thread].first = info;
@@ -893,9 +894,9 @@ Log::setServiceLevel(int service, Level l)
Log::mThreadToLevel[*i].first.mLevel = l;
Log::mThreadToLevel[*i].second = true;
}
Log::touchCount += (short)threads.size();
Log::touchCount.fetch_add((unsigned int)threads.size(), std::memory_order_relaxed);
#endif
// cerr << "**Log::setServiceLevel:touchCount: " << Log::touchCount << "**" << endl;
// cerr << "**Log::setServiceLevel:touchCount: " << Log::touchCount.load(std::memory_order_relaxed) << "**" << endl;
}
Log::LocalLoggerId Log::localLoggerCreate(Log::Type type,

View File

@@ -8,6 +8,7 @@
#include <unistd.h>
#endif
#include <atomic>
#include <set>
#include "rutil/ConfigParse.hxx"
@@ -286,7 +287,7 @@ class Log
protected:
static Mutex _mutex;
static volatile short touchCount;
static std::atomic<unsigned int> touchCount;
static const Data delim;
static unsigned int MaxLineCount;

View File

@@ -29,17 +29,17 @@ class Barrier {
protected:
Condition mCond;
Mutex mMutex;
volatile int mCurId;
volatile int mHaveCnt;
int mCurId;
int mHaveCnt;
int mWantCnt;
public:
static volatile int sPreWaitCnt;
static volatile int sPostWaitCnt;
static int sPreWaitCnt;
static int sPostWaitCnt;
};
volatile int Barrier::sPreWaitCnt = 0;
volatile int Barrier::sPostWaitCnt = 0;
int Barrier::sPreWaitCnt = 0;
int Barrier::sPostWaitCnt = 0;
void
Barrier::sync(int id, bool isMaster)