aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2016-11-27 15:14:36 -0800
committerMatt Corallo <git@bluematt.me>2016-11-27 15:36:44 -0800
commit8b22efb6f7c406951f33a04e84377fd16f02121c (patch)
treece0d5e1558d7343cc48df350f463ac6dbb02284e /src/util.cpp
parent507145d78595e052ce13368e122f72c85093992c (diff)
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.
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util.cpp b/src/util.cpp
index c20ede6221..a1f87a2645 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -259,7 +259,7 @@ bool LogAcceptCategory(const char* category)
* suppress printing of the timestamp when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold it, in the calling context.
*/
-static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine)
+static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
string strStamped;
@@ -286,7 +286,7 @@ static std::string LogTimestampStr(const std::string &str, bool *fStartedNewLine
int LogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written
- static bool fStartedNewLine = true;
+ static std::atomic_bool fStartedNewLine(true);
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);