Skip to content

Commit 8b22efb

Browse files
committed
Make fStartedNewLine an std::atomic_bool
While this doesnt really fix the race of adding timestamps mid-logical-line, it avoids the undefined behavior of using a bool in multiple threads.
1 parent 507145d commit 8b22efb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bool LogAcceptCategory(const char* category)
259259
* suppress printing of the timestamp when multiple calls are made that don't
260260
* end in a newline. Initialize it to true, and hold it, in the calling context.
261261
*/
262-
static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine)
262+
static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
263263
{
264264
string strStamped;
265265

@@ -286,7 +286,7 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
286286
int LogPrintStr(const std::string &str)
287287
{
288288
int ret = 0; // Returns total number of characters written
289-
static bool fStartedNewLine = true;
289+
static std::atomic_bool fStartedNewLine(true);
290290

291291
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);
292292

0 commit comments

Comments
 (0)