From 43163a5a4d0fd3c849dbb2e7070b7ba4f7a70d27 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 11 Feb 2012 20:02:55 +0100 Subject: Macros for manual critical sections --- src/net.h | 6 +++--- src/util.h | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/net.h b/src/net.h index d8b9022276..53e13fd095 100644 --- a/src/net.h +++ b/src/net.h @@ -277,7 +277,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(); @@ -296,7 +296,7 @@ public: vSend.resize(nHeaderStart); nHeaderStart = -1; nMessageStart = -1; - cs_vSend.Leave(); + LEAVE_CRITICAL_SECTION(cs_vSend); if (fDebug) printf("(aborted)\n"); @@ -334,7 +334,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 a48979c0ef..c4ee19fe01 100644 --- a/src/util.h +++ b/src/util.h @@ -254,6 +254,12 @@ public: for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by CRITICAL_BLOCK!" && !fcriticalblockonce)), fcriticalblockonce=false) \ for (CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__); fcriticalblockonce; fcriticalblockonce=false) +#define ENTER_CRITICAL_SECTION(cs) \ + (cs).Enter(#cs, __FILE__, __LINE__) + +#define LEAVE_CRITICAL_SECTION(cs) \ + (cs).Leave() + class CTryCriticalBlock { protected: -- cgit v1.2.3 From 8960f2fc3353d5d7f8b9babd1aaef0e9869e39f4 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 11 Feb 2012 16:35:40 +0100 Subject: Fix wallet locking locking --- src/rpc.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/rpc.cpp b/src/rpc.cpp index 33108948d3..5326cdc2b7 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -1279,33 +1279,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; } -- cgit v1.2.3