Browse Source

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)
0.8
Michael Hendricks 13 years ago
parent
commit
fea25712ca
  1. 3
      src/util.cpp

3
src/util.cpp

@ -25,6 +25,7 @@ namespace boost {
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <stdarg.h> #include <stdarg.h>
@ -209,6 +210,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (fileout) if (fileout)
{ {
static bool fStartedNewLine = true; static bool fStartedNewLine = true;
static boost::mutex mutexDebugLog;
boost::mutex::scoped_lock scoped_lock(mutexDebugLog);
// Debug print useful for profiling // Debug print useful for profiling
if (fLogTimestamps && fStartedNewLine) if (fLogTimestamps && fStartedNewLine)

Loading…
Cancel
Save