aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-12-10 11:34:28 +1000
committerGavin Andresen <gavinandresen@gmail.com>2013-12-10 11:34:28 +1000
commit962b1cf441ceb1de7791d89951a79a54a2fefcd4 (patch)
tree59909d2f6aac84c197f2ecf0440f0159ad294b3f
parent955787f83f49dab298763a3a119766494dede30f (diff)
Fix infinite loop with LogPrint on Windows
Running -printtodebugger -debug (or -debug=lock), compiled with -DDEBUG_LOCKORDER would infinite loop on Windows because every critical section lock/unlock triggers a LogPrint. Solution is to use the raw boost mutex instead of a CCriticalSection.
-rw-r--r--src/util.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/util.cpp b/src/util.cpp
index a8c591cc7a..d975cc9bfb 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -299,27 +299,24 @@ int LogPrint(const char* category, const char* pszFormat, ...)
#ifdef WIN32
if (fPrintToDebugger)
{
- static CCriticalSection cs_OutputDebugStringF;
-
// accumulate and output a line at a time
- {
- LOCK(cs_OutputDebugStringF);
- static std::string buffer;
+ static std::string buffer;
- va_list arg_ptr;
- va_start(arg_ptr, pszFormat);
- buffer += vstrprintf(pszFormat, arg_ptr);
- va_end(arg_ptr);
+ boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
- int line_start = 0, line_end;
- while((line_end = buffer.find('\n', line_start)) != -1)
- {
- OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
- line_start = line_end + 1;
- ret += line_end-line_start;
- }
- buffer.erase(0, line_start);
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ buffer += vstrprintf(pszFormat, arg_ptr);
+ va_end(arg_ptr);
+
+ int line_start = 0, line_end;
+ while((line_end = buffer.find('\n', line_start)) != -1)
+ {
+ OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
+ line_start = line_end + 1;
+ ret += line_end-line_start;
}
+ buffer.erase(0, line_start);
}
#endif
return ret;