aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorMichael Hendricks <michael@ndrix.org>2012-03-02 12:24:38 -0700
committerMichael Hendricks <michael@ndrix.org>2012-05-18 16:19:09 -0600
commitfea25712ca54c4715f874cf3d871e84bbfd83352 (patch)
tree71b57a6f144ed0596007d0a89caddc9b1df72b30 /src/util.cpp
parent660ff174f299a6dfb28f7725dfbb08f140a5474b (diff)
Serialize access to debug.log stream
Acquire an exclusive, advisory lock before sending output to debug.log and release it when we're done. This should avoid output from multiple threads being interspersed in the log file. We can't use CRITICAL_SECTION machinery for this because the debug log is written during startup and shutdown when that machinery is not available. (Thanks to Gavin for pointing out the CRITICAL_SECTION problems based on his earlier work in this area)
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index b0c80f6dfc..d143306aec 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -25,6 +25,7 @@ namespace boost {
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
+#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <stdarg.h>
@@ -209,6 +210,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout)
{
static bool fStartedNewLine = true;
+ static boost::mutex mutexDebugLog;
+ boost::mutex::scoped_lock scoped_lock(mutexDebugLog);
// Debug print useful for profiling
if (fLogTimestamps && fStartedNewLine)