diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-02-17 09:40:00 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-02-17 09:40:00 -0500 |
commit | 6fb186f4bbeb34b4e5c22f909e8d0a1a877f1c44 (patch) | |
tree | d1d195d7941297367db84da93c259034123c0a88 | |
parent | fb811c31fd28d1d637a50f784af620d085fa32d4 (diff) | |
parent | fdb365df0e9bf1b3073ea38212664cb59863bbd0 (diff) |
Merge branch '0.5.0.x' into 0.5.x
-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: |