diff options
author | gavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-11-16 17:41:44 +0000 |
---|---|---|
committer | gavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-11-16 17:41:44 +0000 |
commit | 2f7a9997c88822696edbad38b14c5658c4630e9d (patch) | |
tree | b8da1e674fad25fe25d25ffa76732ba722d4c0f9 /util.cpp | |
parent | 026c5f7617a1a8753ff295a4b5cc1c079e8c3d79 (diff) | |
download | bitcoin-2f7a9997c88822696edbad38b14c5658c4630e9d.tar.xz |
Make OutputDebugStringF thread-safe again (thanks ArtForz for catching)
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@182 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'util.cpp')
-rw-r--r-- | util.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
@@ -145,6 +145,8 @@ int GetRandInt(int nMax) inline int OutputDebugStringF(const char* pszFormat, ...) { + static CCriticalSection cs_OutputDebugStringF; + int ret = 0; if (fPrintToConsole) { @@ -156,29 +158,32 @@ inline int OutputDebugStringF(const char* pszFormat, ...) } else { - // print to debug.log - static FILE* fileout = NULL; - static int64 nOpenTime = 0; - - if (GetTime()-nOpenTime > 10 * 60) + CRITICAL_BLOCK(cs_OutputDebugStringF) { + // print to debug.log + static FILE* fileout = NULL; + static int64 nOpenTime = 0; + + if (GetTime()-nOpenTime > 10 * 60) + { + if (fileout) + fclose(fileout); + char pszFile[MAX_PATH+100]; + GetDataDir(pszFile); + strlcat(pszFile, "/debug.log", sizeof(pszFile)); + fileout = fopen(pszFile, "a"); + nOpenTime = GetTime(); + } if (fileout) - fclose(fileout); - char pszFile[MAX_PATH+100]; - GetDataDir(pszFile); - strlcat(pszFile, "/debug.log", sizeof(pszFile)); - fileout = fopen(pszFile, "a"); - nOpenTime = GetTime(); - } - if (fileout) - { - //// Debug print useful for profiling - //fprintf(fileout, " %"PRI64d" ", GetTimeMillis()); - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - ret = vfprintf(fileout, pszFormat, arg_ptr); - va_end(arg_ptr); - fflush(fileout); + { + //// Debug print useful for profiling + //fprintf(fileout, " %"PRI64d" ", GetTimeMillis()); + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + ret = vfprintf(fileout, pszFormat, arg_ptr); + va_end(arg_ptr); + fflush(fileout); + } } } @@ -186,7 +191,6 @@ inline int OutputDebugStringF(const char* pszFormat, ...) if (fPrintToDebugger) { // accumulate a line at a time - static CCriticalSection cs_OutputDebugStringF; CRITICAL_BLOCK(cs_OutputDebugStringF) { static char pszBuffer[50000]; |