aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorMichael Hendricks <michael@ndrix.org>2012-03-02 12:24:38 -0700
committerLuke Dashjr <luke-jr+git@utopios.org>2012-06-06 19:29:28 +0000
commita0ea95d3ceacea5868b8f921c36bbdddb5dc2b1b (patch)
tree259f8058484ae446ae34df46eb7f010e75f16cbc /src/util.cpp
parent82a227b263fa7d4caee454884661548f7415b9d7 (diff)
downloadbitcoin-a0ea95d3ceacea5868b8f921c36bbdddb5dc2b1b.tar.xz
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 6dc2f3b6da..ccd39aa229 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -22,6 +22,7 @@ namespace boost {
#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
#include <boost/foreach.hpp>
+#include <boost/thread.hpp>
using namespace std;
using namespace boost;
@@ -193,6 +194,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)