From e3ac1001befb7199b8527c881d81e27406f4b2e0 Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Thu, 25 Jun 2015 14:04:16 -0400 Subject: [PATCH] Tidy up locks and locals. --- src/ripple/app/ledger/impl/InboundLedger.cpp | 2 -- src/ripple/app/ledger/impl/LedgerMaster.cpp | 5 +++-- src/ripple/app/misc/SHAMapStoreImp.cpp | 23 ++++++++++---------- src/ripple/basics/base_uint.h | 14 ++++++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/ripple/app/ledger/impl/InboundLedger.cpp b/src/ripple/app/ledger/impl/InboundLedger.cpp index 39585bf5b3..352e081722 100644 --- a/src/ripple/app/ledger/impl/InboundLedger.cpp +++ b/src/ripple/app/ledger/impl/InboundLedger.cpp @@ -466,8 +466,6 @@ void InboundLedger::trigger (Peer::ptr const& peer) Message::pointer packet (std::make_shared ( tmBH, protocol::mtGET_OBJECTS)); { - ScopedLockType sl (mLock); - for (PeerSetMap::iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it) { diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 6cb8aee58b..26016cc07b 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -1024,8 +1024,9 @@ public: setFullLedger(ledger, false, false); mHistLedger = ledger; 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(); getApp().getJobQueue().addJob(jtADVANCE, "tryFill", std::bind ( &LedgerMasterImp::tryFill, this, diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 034772e979..8510a74a1c 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -71,7 +71,7 @@ void SHAMapStoreImp::SavedStateDB::init (BasicConfig const& config, "INSERT INTO DbState VALUES (1, '', '', 0);"; } - + { boost::optional countO; session_ << @@ -277,18 +277,19 @@ SHAMapStoreImp::run() healthy_ = true; validatedLedger_.reset(); - std::unique_lock lock (mutex_); - if (stop_) { - stopped(); - return; + std::unique_lock lock (mutex_); + 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(); if (!lastRotated) diff --git a/src/ripple/basics/base_uint.h b/src/ripple/basics/base_uint.h index bb6dcfaf13..cf3f7f8369 100644 --- a/src/ripple/basics/base_uint.h +++ b/src/ripple/basics/base_uint.h @@ -236,12 +236,17 @@ public: 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++ () { // prefix operator 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) break; @@ -264,7 +269,7 @@ public: for (int i = WIDTH - 1; i >= 0; --i) { std::uint32_t prev = pn[i]; - pn[i] = htobe32 (be32toh (pn[i]) - 1); + pn[i] = hostToBigend (bigendToHost (pn[i]) - 1); if (prev != 0) break; @@ -288,9 +293,10 @@ public: 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; }