Skip to content

Commit

Permalink
Replace boost::call_once with std::call_once
Browse files Browse the repository at this point in the history
Cherry-picked from: 57dae3f
  • Loading branch information
donaloconnor authored and xanimo committed Mar 29, 2024
1 parent 4b084c2 commit 62c126f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,20 @@ instance_of_cinit;
* the mutex).
*/

static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT;
static std::once_flag debugPrintInitFlag;

/**
* We use boost::call_once() to make sure mutexDebugLog and
* We use std::call_once() to make sure mutexDebugLog and
* vMsgsBeforeOpenLog are initialized in a thread-safe manner.
*
* NOTE: fileout, mutexDebugLog and sometimes vMsgsBeforeOpenLog
* are leaked on exit. This is ugly, but will be cleaned up by
* the OS/libc. When the shutdown sequence is fully audited and
* tested, explicit destruction of these objects can be implemented.
*/
static FILE* fileout = NULL;
static boost::mutex* mutexDebugLog = NULL;
static list<string> *vMsgsBeforeOpenLog;
static FILE* fileout = nullptr;
static std::mutex* mutexDebugLog = nullptr;
static std::list<std::string>* vMsgsBeforeOpenLog;

static int FileWriteStr(const std::string &str, FILE *fp)
{
Expand All @@ -188,15 +188,15 @@ static int FileWriteStr(const std::string &str, FILE *fp)

static void DebugPrintInit()
{
assert(mutexDebugLog == NULL);
mutexDebugLog = new boost::mutex();
vMsgsBeforeOpenLog = new list<string>;
assert(mutexDebugLog == nullptr);
mutexDebugLog = new std::mutex();
vMsgsBeforeOpenLog = new std::list<std::string>;
}

void OpenDebugLog()
{
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);

assert(fileout == NULL);
assert(vMsgsBeforeOpenLog);
Expand Down Expand Up @@ -291,8 +291,8 @@ int LogPrintStr(const std::string &str)
}
else if (fPrintToDebugLog)
{
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);

// buffer if we haven't opened the log yet
if (fileout == NULL) {
Expand Down

0 comments on commit 62c126f

Please sign in to comment.