Merge pull request #828 from sipa/fixwalletlock
Fix wallet locking locking
This commit is contained in:
commit
711d5038f5
@ -353,7 +353,7 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
||||||
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
||||||
if (pwalletMain->IsCrypted())
|
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")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -1537,35 +1537,41 @@ void ThreadTopUpKeyPool(void* parg)
|
|||||||
|
|
||||||
void ThreadCleanWalletPassphrase(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)
|
if (nWalletUnlockTime == 0)
|
||||||
{
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
|
||||||
{
|
{
|
||||||
nWalletUnlockTime = nMyWakeTime;
|
nWalletUnlockTime = nMyWakeTime;
|
||||||
}
|
|
||||||
|
|
||||||
while (GetTime() < nWalletUnlockTime)
|
do
|
||||||
Sleep(GetTime() - nWalletUnlockTime);
|
{
|
||||||
|
if (nWalletUnlockTime==0)
|
||||||
|
break;
|
||||||
|
int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
|
||||||
|
if (nToSleep <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
|
Sleep(nToSleep);
|
||||||
|
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
|
|
||||||
|
} while(1);
|
||||||
|
|
||||||
|
if (nWalletUnlockTime)
|
||||||
{
|
{
|
||||||
nWalletUnlockTime = 0;
|
nWalletUnlockTime = 0;
|
||||||
|
pwalletMain->Lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
|
||||||
{
|
{
|
||||||
if (nWalletUnlockTime < nMyWakeTime)
|
if (nWalletUnlockTime < nMyWakeTime)
|
||||||
nWalletUnlockTime = nMyWakeTime;
|
nWalletUnlockTime = nMyWakeTime;
|
||||||
}
|
}
|
||||||
delete (int*)parg;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pwalletMain->Lock();
|
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
|
|
||||||
delete (int*)parg;
|
delete (int*)parg;
|
||||||
}
|
}
|
||||||
@ -1655,9 +1661,9 @@ Value walletlock(const Array& params, bool fHelp)
|
|||||||
if (!pwalletMain->IsCrypted())
|
if (!pwalletMain->IsCrypted())
|
||||||
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
||||||
|
|
||||||
pwalletMain->Lock();
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
||||||
{
|
{
|
||||||
|
pwalletMain->Lock();
|
||||||
nWalletUnlockTime = 0;
|
nWalletUnlockTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ public:
|
|||||||
|
|
||||||
void BeginMessage(const char* pszCommand)
|
void BeginMessage(const char* pszCommand)
|
||||||
{
|
{
|
||||||
cs_vSend.Enter("cs_vSend", __FILE__, __LINE__);
|
ENTER_CRITICAL_SECTION(cs_vSend);
|
||||||
if (nHeaderStart != -1)
|
if (nHeaderStart != -1)
|
||||||
AbortMessage();
|
AbortMessage();
|
||||||
nHeaderStart = vSend.size();
|
nHeaderStart = vSend.size();
|
||||||
@ -298,7 +298,7 @@ public:
|
|||||||
vSend.resize(nHeaderStart);
|
vSend.resize(nHeaderStart);
|
||||||
nHeaderStart = -1;
|
nHeaderStart = -1;
|
||||||
nMessageStart = -1;
|
nMessageStart = -1;
|
||||||
cs_vSend.Leave();
|
LEAVE_CRITICAL_SECTION(cs_vSend);
|
||||||
|
|
||||||
if (fDebug)
|
if (fDebug)
|
||||||
printf("(aborted)\n");
|
printf("(aborted)\n");
|
||||||
@ -336,7 +336,7 @@ public:
|
|||||||
|
|
||||||
nHeaderStart = -1;
|
nHeaderStart = -1;
|
||||||
nMessageStart = -1;
|
nMessageStart = -1;
|
||||||
cs_vSend.Leave();
|
LEAVE_CRITICAL_SECTION(cs_vSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndMessageAbortIfEmpty()
|
void EndMessageAbortIfEmpty()
|
||||||
|
@ -218,6 +218,12 @@ public:
|
|||||||
#define CRITICAL_BLOCK(cs) \
|
#define CRITICAL_BLOCK(cs) \
|
||||||
if (CCriticalBlock criticalblock = CCriticalBlock(cs, #cs, __FILE__, __LINE__))
|
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
|
class CTryCriticalBlock
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user