Tidy up locks and locals.

This commit is contained in:
Tom Ritchford
2015-06-25 14:04:16 -04:00
committed by Vinnie Falco
parent 67f2a5d9d6
commit e3ac1001be
4 changed files with 25 additions and 19 deletions

View File

@@ -466,8 +466,6 @@ void InboundLedger::trigger (Peer::ptr const& peer)
Message::pointer packet (std::make_shared <Message> ( Message::pointer packet (std::make_shared <Message> (
tmBH, protocol::mtGET_OBJECTS)); tmBH, protocol::mtGET_OBJECTS));
{ {
ScopedLockType sl (mLock);
for (PeerSetMap::iterator it = mPeers.begin (), end = mPeers.end (); for (PeerSetMap::iterator it = mPeers.begin (), end = mPeers.end ();
it != end; ++it) it != end; ++it)
{ {

View File

@@ -1024,8 +1024,9 @@ public:
setFullLedger(ledger, false, false); setFullLedger(ledger, false, false);
mHistLedger = ledger; mHistLedger = ledger;
if ((mFillInProgress == 0) && (Ledger::getHashByIndex(ledger->getLedgerSeq() - 1) == ledger->getParentHash())) if ((mFillInProgress == 0) && (Ledger::getHashByIndex(ledger->getLedgerSeq() - 1) == ledger->getParentHash()))
{ // Previous ledger is in DB {
ScopedLockType sl(m_mutex); // Previous ledger is in DB
ScopedLockType lock (m_mutex);
mFillInProgress = ledger->getLedgerSeq(); mFillInProgress = ledger->getLedgerSeq();
getApp().getJobQueue().addJob(jtADVANCE, "tryFill", std::bind ( getApp().getJobQueue().addJob(jtADVANCE, "tryFill", std::bind (
&LedgerMasterImp::tryFill, this, &LedgerMasterImp::tryFill, this,

View File

@@ -71,7 +71,7 @@ void SHAMapStoreImp::SavedStateDB::init (BasicConfig const& config,
"INSERT INTO DbState VALUES (1, '', '', 0);"; "INSERT INTO DbState VALUES (1, '', '', 0);";
} }
{ {
boost::optional<std::int64_t> countO; boost::optional<std::int64_t> countO;
session_ << session_ <<
@@ -277,18 +277,19 @@ SHAMapStoreImp::run()
healthy_ = true; healthy_ = true;
validatedLedger_.reset(); validatedLedger_.reset();
std::unique_lock <std::mutex> lock (mutex_);
if (stop_)
{ {
stopped(); std::unique_lock <std::mutex> lock (mutex_);
return; if (stop_)
{
stopped();
return;
}
cond_.wait (lock);
if (newLedger_)
validatedLedger_ = std::move (newLedger_);
else
continue;
} }
cond_.wait (lock);
if (newLedger_)
validatedLedger_ = std::move (newLedger_);
else
continue;
lock.unlock();
LedgerIndex validatedSeq = validatedLedger_->getLedgerSeq(); LedgerIndex validatedSeq = validatedLedger_->getLedgerSeq();
if (!lastRotated) if (!lastRotated)

View File

@@ -236,12 +236,17 @@ public:
return *this; return *this;
} }
// be32toh and htobe32 are macros that somehow cause shadowing
// warnings in this header file, so we hide them...
static uint32_t bigendToHost (uint32_t x) { return be32toh(x); }
static uint32_t hostToBigend (uint32_t x) { return htobe32(x); }
base_uint& operator++ () base_uint& operator++ ()
{ {
// prefix operator // prefix operator
for (int i = WIDTH - 1; i >= 0; --i) for (int i = WIDTH - 1; i >= 0; --i)
{ {
pn[i] = htobe32 (be32toh (pn[i]) + 1); pn[i] = hostToBigend (bigendToHost (pn[i]) + 1);
if (pn[i] != 0) if (pn[i] != 0)
break; break;
@@ -264,7 +269,7 @@ public:
for (int i = WIDTH - 1; i >= 0; --i) for (int i = WIDTH - 1; i >= 0; --i)
{ {
std::uint32_t prev = pn[i]; std::uint32_t prev = pn[i];
pn[i] = htobe32 (be32toh (pn[i]) - 1); pn[i] = hostToBigend (bigendToHost (pn[i]) - 1);
if (prev != 0) if (prev != 0)
break; break;
@@ -288,9 +293,10 @@ public:
for (int i = WIDTH; i--;) for (int i = WIDTH; i--;)
{ {
std::uint64_t n = carry + be32toh (pn[i]) + be32toh (b.pn[i]); std::uint64_t n = carry + bigendToHost (pn[i]) +
bigendToHost (b.pn[i]);
pn[i] = htobe32 (n & 0xffffffff); pn[i] = hostToBigend (n & 0xffffffff);
carry = n >> 32; carry = n >> 32;
} }