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.
This commit is contained in:
parent
955787f83f
commit
962b1cf441
1 changed files with 15 additions and 18 deletions
33
src/util.cpp
33
src/util.cpp
|
@ -299,27 +299,24 @@ int LogPrint(const char* category, const char* pszFormat, ...)
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (fPrintToDebugger)
|
if (fPrintToDebugger)
|
||||||
{
|
{
|
||||||
static CCriticalSection cs_OutputDebugStringF;
|
|
||||||
|
|
||||||
// accumulate and output a line at a time
|
// accumulate and output a line at a time
|
||||||
|
static std::string buffer;
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
LOCK(cs_OutputDebugStringF);
|
OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
|
||||||
static std::string buffer;
|
line_start = line_end + 1;
|
||||||
|
ret += line_end-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);
|
|
||||||
}
|
}
|
||||||
|
buffer.erase(0, line_start);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue