From: Pieter Wuille Date: Sat, 11 Feb 2012 15:35:40 +0000 (+0100) Subject: Fix wallet locking locking X-Git-Tag: v0.4.0-unstable~129^2~217^2~1 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b0529ffd951fdaa7ecc823381a6a7b0c88b5b2b0 Fix wallet locking locking --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5d38f04..8f98135 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1539,33 +1539,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; }