From 17a2587bf10970383fbde7fae3b914c812ca173a Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 9 Aug 2015 00:46:42 +0300 Subject: [PATCH 1/2] more trylock+wait: rpc, GetHeight --- src/main.cpp | 7 +++++-- src/rpcserver.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 76a5f8f9e868e..11b27aa172435 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,8 +302,11 @@ CNodeState *State(NodeId pnode) { int GetHeight() { - LOCK(cs_main); - return chainActive.Height(); + while(true){ + TRY_LOCK(cs_main, lockMain); + if(!lockMain) { MilliSleep(10); continue; } + return chainActive.Height(); + } } void UpdatePreferredDownload(CNode* node, CNodeState* state) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d74fe109d5ab1..a862954582b7c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -1017,8 +1017,17 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s LOCK(cs_main); result = pcmd->actor(params, false); } else { - LOCK2(cs_main, pwalletMain->cs_wallet); - result = pcmd->actor(params, false); + while (true) { + TRY_LOCK(cs_main, lockMain); + if(!lockMain) { MilliSleep(50); continue; } + while (true) { + TRY_LOCK(pwalletMain->cs_wallet, lockWallet); + if(!lockMain) { MilliSleep(50); continue; } + result = pcmd->actor(params, false); + break; + } + break; + } } #else // ENABLE_WALLET else { From 84264b032795ed74e5d7fa46c70a93e130ba3aab Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 9 Aug 2015 00:48:09 +0300 Subject: [PATCH 2/2] millisleep 10->50 on trylock+wait --- src/darksend.cpp | 4 ++-- src/main.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/darksend.cpp b/src/darksend.cpp index 38245ca7bb9f9..4762c1130d55e 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -434,7 +434,7 @@ bool CDarksendPool::SetCollateralAddress(std::string strAddress){ void CDarksendPool::UnlockCoins(){ while(true) { TRY_LOCK(pwalletMain->cs_wallet, lockWallet); - if(!lockWallet) {MilliSleep(10); continue;} + if(!lockWallet) {MilliSleep(50); continue;} BOOST_FOREACH(CTxIn v, lockedCoins) pwalletMain->UnlockCoin(v.prevout); break; @@ -1161,7 +1161,7 @@ void CDarksendPool::SendDarksendDenominate(std::vector& vin, std::vector< while(true){ TRY_LOCK(cs_main, lockMain); - if(!lockMain) { MilliSleep(10); continue;} + if(!lockMain) { MilliSleep(50); continue;} if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL, false, true)){ LogPrintf("dsi -- transaction not valid! %s \n", tx.ToString()); UnlockCoins(); diff --git a/src/main.cpp b/src/main.cpp index 11b27aa172435..5cc51d0f06364 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -304,7 +304,7 @@ int GetHeight() { while(true){ TRY_LOCK(cs_main, lockMain); - if(!lockMain) { MilliSleep(10); continue; } + if(!lockMain) { MilliSleep(50); continue; } return chainActive.Height(); } } @@ -2621,7 +2621,7 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) { bool fInitialDownload; while(true) { TRY_LOCK(cs_main, lockMain); - if(!lockMain) { MilliSleep(10); continue; } + if(!lockMain) { MilliSleep(50); continue; } pindexMostWork = FindMostWorkChain(); @@ -3269,7 +3269,7 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis while(true) { TRY_LOCK(cs_main, lockMain); - if(!lockMain) { MilliSleep(10); continue; } + if(!lockMain) { MilliSleep(50); continue; } MarkBlockAsReceived(pblock->GetHash()); if (!checked) {