diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 30 | ||||
-rw-r--r-- | src/net.h | 6 | ||||
-rw-r--r-- | src/util.h | 6 |
3 files changed, 23 insertions, 19 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 506e194612..57abe8e4f4 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1409,33 +1409,31 @@ void ThreadCleanWalletPassphrase(void* parg) { int64 nMyWakeTime = GetTime() + *((int*)parg); + ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); + if (nWalletUnlockTime == 0) { - CRITICAL_BLOCK(cs_nWalletUnlockTime) - { - nWalletUnlockTime = nMyWakeTime; - } + nWalletUnlockTime = nMyWakeTime; while (GetTime() < nWalletUnlockTime) - Sleep(GetTime() - nWalletUnlockTime); - - CRITICAL_BLOCK(cs_nWalletUnlockTime) { - nWalletUnlockTime = 0; + int64 nToSleep = GetTime() - nWalletUnlockTime; + + LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime); + Sleep(nToSleep); + ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); } + + nWalletUnlockTime = 0; + pwalletMain->Lock(); } else { - CRITICAL_BLOCK(cs_nWalletUnlockTime) - { - if (nWalletUnlockTime < nMyWakeTime) - nWalletUnlockTime = nMyWakeTime; - } - delete (int*)parg; - return; + if (nWalletUnlockTime < nMyWakeTime) + nWalletUnlockTime = nMyWakeTime; } - pwalletMain->Lock(); + LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime); delete (int*)parg; } @@ -284,7 +284,7 @@ public: void BeginMessage(const char* pszCommand) { - cs_vSend.Enter("cs_vSend", __FILE__, __LINE__); + ENTER_CRITICAL_SECTION(cs_vSend); if (nHeaderStart != -1) AbortMessage(); nHeaderStart = vSend.size(); @@ -303,7 +303,7 @@ public: vSend.resize(nHeaderStart); nHeaderStart = -1; nMessageStart = -1; - cs_vSend.Leave(); + LEAVE_CRITICAL_SECTION(cs_vSend); if (fDebug) printf("(aborted)\n"); @@ -341,7 +341,7 @@ public: nHeaderStart = -1; nMessageStart = -1; - cs_vSend.Leave(); + LEAVE_CRITICAL_SECTION(cs_vSend); } void EndMessageAbortIfEmpty() diff --git a/src/util.h b/src/util.h index df093108ee..15a45ba7d7 100644 --- a/src/util.h +++ b/src/util.h @@ -258,6 +258,12 @@ public: #define CRITICAL_BLOCK(cs) \ if (CCriticalBlock criticalblock = CCriticalBlock(cs, #cs, __FILE__, __LINE__)) +#define ENTER_CRITICAL_SECTION(cs) \ + (cs).Enter(#cs, __FILE__, __LINE__) + +#define LEAVE_CRITICAL_SECTION(cs) \ + (cs).Leave() + class CTryCriticalBlock { protected: |