Use standard C++ types instead of type aliases:

* Remove ripple::RippleMutex and ripple::RippleRecursiveMutex
  and use std::mutex and std::recursive_mutex respectively.
* Use std::lock_guard instead of std::unique_lock when the
  additional features of std::unique_lock are not needed.
This commit is contained in:
Nik Bougalis
2015-09-29 15:07:03 -07:00
committed by Vinnie Falco
parent 333ba69d60
commit f424ae6942
25 changed files with 100 additions and 158 deletions

View File

@@ -28,6 +28,7 @@
#include <boost/format.hpp>
#include <boost/tokenizer.hpp>
#include <algorithm>
#include <mutex>
namespace ripple {
/** Track the list of "amendments"
@@ -43,9 +44,7 @@ protected:
using amendmentMap_t = hash_map<uint256, AmendmentState>;
using amendmentList_t = hash_set<uint256>;
using LockType = RippleMutex;
using ScopedLockType = std::lock_guard <LockType>;
LockType mLock;
std::mutex mLock;
amendmentMap_t m_amendmentMap;
std::uint32_t m_lastUpdateSeq;
@@ -213,7 +212,7 @@ AmendmentTableImpl::getExisting (uint256 const& amendmentHash)
uint256
AmendmentTableImpl::get (std::string const& name)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto const& e : m_amendmentMap)
{
@@ -237,7 +236,7 @@ AmendmentTableImpl::addKnown (AmendmentName const& name)
throw std::runtime_error (errorMsg);
}
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState& amendment = getCreate (name.id ());
if (!name.friendlyName ().empty ())
@@ -250,7 +249,7 @@ AmendmentTableImpl::addKnown (AmendmentName const& name)
bool
AmendmentTableImpl::veto (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState& s = getCreate (amendment);
if (s.mVetoed)
@@ -263,7 +262,7 @@ AmendmentTableImpl::veto (uint256 const& amendment)
bool
AmendmentTableImpl::unVeto (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState* s = getExisting (amendment);
if (!s || !s->mVetoed)
@@ -276,7 +275,7 @@ AmendmentTableImpl::unVeto (uint256 const& amendment)
bool
AmendmentTableImpl::enable (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState& s = getCreate (amendment);
if (s.mEnabled)
@@ -289,7 +288,7 @@ AmendmentTableImpl::enable (uint256 const& amendment)
bool
AmendmentTableImpl::disable (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState* s = getExisting (amendment);
if (!s || !s->mEnabled)
@@ -302,7 +301,7 @@ AmendmentTableImpl::disable (uint256 const& amendment)
bool
AmendmentTableImpl::isEnabled (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState* s = getExisting (amendment);
return s && s->mEnabled;
}
@@ -310,7 +309,7 @@ AmendmentTableImpl::isEnabled (uint256 const& amendment)
bool
AmendmentTableImpl::isSupported (uint256 const& amendment)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
AmendmentState* s = getExisting (amendment);
return s && s->mSupported;
}
@@ -319,7 +318,7 @@ AmendmentTableImpl::amendmentList_t
AmendmentTableImpl::getVetoed ()
{
amendmentList_t ret;
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto const& e : m_amendmentMap)
{
if (e.second.mVetoed)
@@ -332,7 +331,7 @@ AmendmentTableImpl::amendmentList_t
AmendmentTableImpl::getEnabled ()
{
amendmentList_t ret;
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto const& e : m_amendmentMap)
{
if (e.second.mEnabled)
@@ -345,7 +344,7 @@ AmendmentTableImpl::amendmentList_t
AmendmentTableImpl::getDesired (enabledAmendments_t const& enabled)
{
amendmentList_t ret;
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto const& e : m_amendmentMap)
{
@@ -360,7 +359,7 @@ AmendmentTableImpl::getDesired (enabledAmendments_t const& enabled)
void
AmendmentTableImpl::setEnabled (const std::vector<uint256>& amendments)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto& e : m_amendmentMap)
{
e.second.mEnabled = false;
@@ -374,7 +373,7 @@ AmendmentTableImpl::setEnabled (const std::vector<uint256>& amendments)
void
AmendmentTableImpl::setSupported (const std::vector<uint256>& amendments)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto &e : m_amendmentMap)
{
e.second.mSupported = false;
@@ -443,7 +442,7 @@ AmendmentTableImpl::doVoting (
std::map <uint256, std::uint32_t> actions;
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
// process all amendments we know of
for (auto const& entry : m_amendmentMap)
@@ -486,7 +485,7 @@ AmendmentTableImpl::doVoting (
bool
AmendmentTableImpl::needValidatedLedger (LedgerIndex ledgerSeq)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
// Is there a ledger in which an amendment could have been enabled
// between these two ledger sequences?
@@ -498,7 +497,7 @@ void
AmendmentTableImpl::doValidatedLedger (LedgerIndex ledgerSeq,
enabledAmendments_t enabled)
{
ScopedLockType sl (mLock);
std::lock_guard <std::mutex> sl (mLock);
for (auto& e : m_amendmentMap)
e.second.mEnabled = (enabled.count (e.first) != 0);
@@ -509,7 +508,7 @@ AmendmentTableImpl::getJson (int)
{
Json::Value ret(Json::objectValue);
{
ScopedLockType sl(mLock);
std::lock_guard <std::mutex> sl(mLock);
for (auto const& e : m_amendmentMap)
{
setJson (ret[to_string (e.first)] = Json::objectValue, e.second);
@@ -536,7 +535,7 @@ AmendmentTableImpl::getJson (uint256 const& amendmentID)
Json::Value& jAmendment = (ret[to_string (amendmentID)] = Json::objectValue);
{
ScopedLockType sl(mLock);
std::lock_guard <std::mutex> sl(mLock);
AmendmentState& amendmentState = getCreate (amendmentID);
setJson (jAmendment, amendmentState);

View File

@@ -70,6 +70,7 @@
#include <boost/optional.hpp>
#include <tuple>
#include <condition_variable>
#include <mutex>
namespace ripple {
@@ -426,8 +427,7 @@ private:
using subRpcMapType = hash_map<std::string, InfoSub::pointer>;
// XXX Split into more locks.
using LockType = RippleRecursiveMutex;
using ScopedLockType = std::lock_guard <LockType>;
using ScopedLockType = std::lock_guard <std::recursive_mutex>;
Application& app_;
clock_type& m_clock;
@@ -435,7 +435,7 @@ private:
std::unique_ptr <LocalTxs> m_localTX;
LockType mSubLock;
std::recursive_mutex mSubLock;
std::atomic<OperatingMode> mMode;

View File

@@ -43,6 +43,7 @@
#include <boost/regex.hpp>
#include <boost/optional.hpp>
#include <fstream>
#include <mutex>
namespace ripple {
@@ -205,13 +206,8 @@ private:
private:
Application& app_;
typedef RippleMutex FetchLockType;
typedef std::lock_guard <FetchLockType> ScopedFetchLockType;
FetchLockType mFetchLock;
typedef RippleRecursiveMutex UNLLockType;
typedef std::lock_guard <UNLLockType> ScopedUNLLockType;
UNLLockType mUNLLock;
std::mutex mFetchLock;
std::recursive_mutex mUNLLock;
// VFALCO TODO Replace ptime with beast::Time
// Misc persistent information
@@ -485,14 +481,14 @@ void UniqueNodeListImp::start()
void UniqueNodeListImp::insertEphemeralKey (PublicKey pk, std::string comment)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
ephemeralValidatorKeys_.insert (std::make_pair(std::move(pk), std::move(comment)));
}
void UniqueNodeListImp::deleteEphemeralKey (PublicKey const& pk)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
ephemeralValidatorKeys_.erase (pk);
}
@@ -596,7 +592,7 @@ void UniqueNodeListImp::nodeRemovePublic (RippleAddress const& naNodePublic)
// YYY Only dirty on successful delete.
fetchDirty ();
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
mUNL.erase (naNodePublic.humanNodePublic ());
}
@@ -646,7 +642,7 @@ bool UniqueNodeListImp::nodeInUNL (RippleAddress const& naNodePublic)
auto const& blob = naNodePublic.getNodePublic();
PublicKey const pk (Slice(blob.data(), blob.size()));
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
if (ephemeralValidatorKeys_.find (pk) != ephemeralValidatorKeys_.end())
{
@@ -660,7 +656,7 @@ bool UniqueNodeListImp::nodeInUNL (RippleAddress const& naNodePublic)
bool UniqueNodeListImp::nodeInCluster (RippleAddress const& naNodePublic)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
return m_clusterNodes.end () != m_clusterNodes.find (naNodePublic);
}
@@ -668,7 +664,7 @@ bool UniqueNodeListImp::nodeInCluster (RippleAddress const& naNodePublic)
bool UniqueNodeListImp::nodeInCluster (RippleAddress const& naNodePublic, std::string& name)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
std::map<RippleAddress, ClusterNodeStatus>::iterator it = m_clusterNodes.find (naNodePublic);
if (it == m_clusterNodes.end ())
@@ -682,7 +678,7 @@ bool UniqueNodeListImp::nodeInCluster (RippleAddress const& naNodePublic, std::s
bool UniqueNodeListImp::nodeUpdate (RippleAddress const& naNodePublic, ClusterNodeStatus const& cnsStatus)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
return m_clusterNodes[naNodePublic].update(cnsStatus);
}
@@ -693,7 +689,7 @@ UniqueNodeListImp::getClusterStatus()
{
std::map<RippleAddress, ClusterNodeStatus> ret;
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
ret = m_clusterNodes;
}
return ret;
@@ -707,7 +703,7 @@ std::uint32_t UniqueNodeListImp::getClusterFee()
std::vector<std::uint32_t> fees;
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
{
for (std::map<RippleAddress, ClusterNodeStatus>::iterator it = m_clusterNodes.begin(),
end = m_clusterNodes.end(); it != end; ++it)
@@ -728,7 +724,7 @@ std::uint32_t UniqueNodeListImp::getClusterFee()
void UniqueNodeListImp::addClusterStatus (Json::Value& obj)
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
if (m_clusterNodes.size() > 1) // nodes other than us
{
auto const now = app_.timeKeeper().now().time_since_epoch().count();
@@ -925,7 +921,7 @@ Json::Value UniqueNodeListImp::getUnlJson()
ret.append (node);
}
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
for (auto const& key : ephemeralValidatorKeys_)
{
@@ -1038,7 +1034,7 @@ void UniqueNodeListImp::trustedLoad()
}
auto db = app_.getWalletDB ().checkoutDb ();
ScopedUNLLockType slUNL (mUNLLock);
std::lock_guard <std::recursive_mutex> slUNL (mUNLLock);
mUNL.clear ();
@@ -1414,7 +1410,7 @@ void UniqueNodeListImp::scoreCompute()
}
{
ScopedUNLLockType sl (mUNLLock);
std::lock_guard <std::recursive_mutex> sl (mUNLLock);
// XXX Should limit to scores above a certain minimum and limit to a certain number.
mUNL.swap (usUNL);
@@ -1647,7 +1643,7 @@ void UniqueNodeListImp::fetchNext()
bool bFull;
{
ScopedFetchLockType sl (mFetchLock);
std::lock_guard <std::mutex> sl (mFetchLock);
bFull = (mFetchActive == NODE_FETCH_JOBS);
}
@@ -1685,7 +1681,7 @@ void UniqueNodeListImp::fetchNext()
if (!strDomain.empty ())
{
ScopedFetchLockType sl (mFetchLock);
std::lock_guard <std::mutex> sl (mFetchLock);
bFull = (mFetchActive == NODE_FETCH_JOBS);
@@ -1761,7 +1757,7 @@ void UniqueNodeListImp::fetchDirty()
void UniqueNodeListImp::fetchFinish()
{
{
ScopedFetchLockType sl (mFetchLock);
std::lock_guard <std::mutex> sl (mFetchLock);
mFetchActive--;
}