aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-02-16 03:30:26 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2012-02-16 03:30:26 -0800
commit711d5038f5c987f58862fd78a980d578d4183dbe (patch)
tree98bed03d53ec0ffc3038c176997252d26a646233
parentc85c37acb16df6c8911c81689932890eec6864a3 (diff)
parentaa625ed6ed0ec7060859225cf9d43799eed5a799 (diff)
Merge pull request #828 from sipa/fixwalletlock
Fix wallet locking locking
-rw-r--r--src/bitcoinrpc.cpp40
-rw-r--r--src/net.h6
-rw-r--r--src/util.h6
3 files changed, 32 insertions, 20 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 5d38f042f9..cf5bc64bb9 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -353,7 +353,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
if (pwalletMain->IsCrypted())
- obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
+ obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
@@ -1537,35 +1537,41 @@ void ThreadTopUpKeyPool(void* parg)
void ThreadCleanWalletPassphrase(void* parg)
{
- int64 nMyWakeTime = GetTime() + *((int*)parg);
+ int64 nMyWakeTime = GetTimeMillis() + *((int*)parg) * 1000;
+
+ ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
if (nWalletUnlockTime == 0)
{
- CRITICAL_BLOCK(cs_nWalletUnlockTime)
+ nWalletUnlockTime = nMyWakeTime;
+
+ do
{
- nWalletUnlockTime = nMyWakeTime;
- }
+ if (nWalletUnlockTime==0)
+ break;
+ int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
+ if (nToSleep <= 0)
+ break;
+
+ LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
+ Sleep(nToSleep);
+ ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
- while (GetTime() < nWalletUnlockTime)
- Sleep(GetTime() - nWalletUnlockTime);
+ } while(1);
- CRITICAL_BLOCK(cs_nWalletUnlockTime)
+ if (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;
}
@@ -1655,9 +1661,9 @@ Value walletlock(const Array& params, bool fHelp)
if (!pwalletMain->IsCrypted())
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
- pwalletMain->Lock();
CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
+ pwalletMain->Lock();
nWalletUnlockTime = 0;
}
diff --git a/src/net.h b/src/net.h
index 2be9541cd1..a66bc15438 100644
--- a/src/net.h
+++ b/src/net.h
@@ -279,7 +279,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();
@@ -298,7 +298,7 @@ public:
vSend.resize(nHeaderStart);
nHeaderStart = -1;
nMessageStart = -1;
- cs_vSend.Leave();
+ LEAVE_CRITICAL_SECTION(cs_vSend);
if (fDebug)
printf("(aborted)\n");
@@ -336,7 +336,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 8dcedb147b..ddc8791b38 100644
--- a/src/util.h
+++ b/src/util.h
@@ -218,6 +218,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: