Remove unnecessary allocation/deallocation from masterLock

* Add make_lock.
* Rename Application::LockType to Application::MutexType:
* Rename getMasterLock to getMasterMutex.
* Use getMasterMutex and make_lock.
* Remove unused code.
This commit is contained in:
Howard Hinnant
2015-03-18 12:29:40 -04:00
committed by Tom Ritchford
parent 698fe73608
commit a61ffab3f9
20 changed files with 85 additions and 41 deletions

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2015, Howard Hinnant <howard.hinnant@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_UTILITY_MAKE_LOCK_H_INCLUDED
#define BEAST_UTILITY_MAKE_LOCK_H_INCLUDED
#include <mutex>
#include <utility>
namespace beast {
template <class Mutex, class ...Args>
inline
std::unique_lock<Mutex>
make_lock(Mutex& mutex, Args&&... args)
{
return std::unique_lock<Mutex>(mutex, std::forward<Args>(args)...);
}
} // beast
#endif

View File

@@ -18,7 +18,6 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/module/core/text/LexicalCast.h>
#include <ripple/app/consensus/DisputedTx.h>
#include <ripple/app/consensus/LedgerConsensus.h>
#include <ripple/app/ledger/InboundLedgers.h>
@@ -42,6 +41,8 @@
#include <ripple/overlay/predicates.h>
#include <ripple/protocol/STValidation.h>
#include <ripple/protocol/UintTypes.h>
#include <beast/module/core/text/LexicalCast.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -976,8 +977,7 @@ private:
{
{
Application::ScopedLockType lock
(getApp ().getMasterLock ());
std::lock_guard<Application::MutexType> lock(getApp().getMasterMutex());
// put our set where others can get it later
if (set->getHash ().isNonZero ())
@@ -1137,11 +1137,10 @@ private:
}
{
Application::ScopedLockType lock
(getApp ().getMasterLock ());
auto lock = beast::make_lock(getApp().getMasterMutex(), std::defer_lock);
LedgerMaster::ScopedLockType sl
(getApp().getLedgerMaster ().peekMutex ());
(getApp().getLedgerMaster ().peekMutex (), std::defer_lock);
std::lock(lock, sl);
// Apply transactions from the old open ledger
Ledger::pointer oldOL = getApp().getLedgerMaster().getCurrentLedger();

View File

@@ -248,7 +248,7 @@ private:
public:
Logs& m_logs;
beast::Journal m_journal;
Application::LockType m_masterMutex;
Application::MutexType m_masterMutex;
// Required by the SHAMapStore
TransactionMaster m_txMaster;
@@ -524,7 +524,7 @@ public:
return *m_nodeStore;
}
Application::LockType& getMasterLock ()
Application::MutexType& getMasterMutex ()
{
return m_masterMutex;
}

View File

@@ -70,7 +70,7 @@ class Application : public beast::PropertyStream::Source
public:
/* VFALCO NOTE
The master lock protects:
The master mutex protects:
- The open ledger
- Server global state
@@ -79,16 +79,8 @@ public:
other things
*/
typedef std::recursive_mutex LockType;
typedef std::unique_lock <LockType> ScopedLockType;
typedef std::unique_ptr <ScopedLockType> ScopedLock;
virtual LockType& getMasterLock () = 0;
ScopedLock masterLock()
{
return std::make_unique<ScopedLockType> (getMasterLock());
}
using MutexType = std::recursive_mutex;
virtual MutexType& getMasterMutex () = 0;
public:
Application ();

View File

@@ -60,6 +60,7 @@
#include <beast/module/core/thread/DeadlineTimer.h>
#include <beast/module/core/system/SystemStats.h>
#include <beast/cxx14/memory.h> // <memory>
#include <beast/utility/make_lock.h>
#include <boost/optional.hpp>
#include <tuple>
@@ -652,7 +653,7 @@ void NetworkOPsImp::onDeadlineTimer (beast::DeadlineTimer& timer)
void NetworkOPsImp::processHeartbeatTimer ()
{
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
// VFALCO NOTE This is for diagnosing a crash on exit
Application& app (getApp ());
@@ -1004,7 +1005,7 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
}
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
bool didApply;
TER r = m_ledgerMaster.doTransaction (
@@ -1600,7 +1601,7 @@ void NetworkOPsImp::processTrustedProposal (
uint256 checkLedger, bool sigGood)
{
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
bool relay = true;

View File

@@ -24,6 +24,7 @@
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/tx/TransactionAcquire.h>
#include <ripple/overlay/Overlay.h>
#include <beast/utility/make_lock.h>
#include <memory>
namespace ripple {
@@ -52,7 +53,7 @@ TransactionAcquire::~TransactionAcquire ()
static void TACompletionHandler (uint256 hash, std::shared_ptr<SHAMap> map)
{
{
Application::ScopedLockType lock (getApp ().getMasterLock ());
std::lock_guard<Application::MutexType> lock(getApp().getMasterMutex());
getApp().getOPs ().mapComplete (hash, map);
@@ -88,7 +89,7 @@ void TransactionAcquire::onTimer (bool progress, ScopedLockType& psl)
WriteLog (lsWARNING, TransactionAcquire) << "Ten timeouts on TX set " << getHash ();
psl.unlock();
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
if (getApp().getOPs ().stillNeedTXSet (mHash))
{

View File

@@ -1478,7 +1478,7 @@ PeerImp::checkPropose (Job& job,
uint256 consensusLCL;
if (! set.has_previousledger() || ! isTrusted)
{
Application::ScopedLockType lock (getApp ().getMasterLock ());
std::lock_guard<Application::MutexType> lock(getApp().getMasterMutex());
consensusLCL = getApp().getOPs ().getConsensusLCL ();
}
@@ -1614,7 +1614,7 @@ PeerImp::getLedger (std::shared_ptr<protocol::TMGetLedger> const& m)
memcpy (txHash.begin (), packet.ledgerhash ().data (), 32);
{
Application::ScopedLockType lock (getApp ().getMasterLock ());
std::lock_guard<Application::MutexType> lock(getApp().getMasterMutex());
map = getApp().getOPs ().getTXMap (txHash);
}
@@ -1976,7 +1976,7 @@ PeerImp::peerTXData (Job&, uint256 const& hash,
SHAMapAddNode san;
{
Application::ScopedLockType lock (getApp ().getMasterLock ());
std::lock_guard<Application::MutexType> lock(getApp().getMasterMutex());
san = getApp().getOPs().gotTXData (shared_from_this(),
hash, nodeIDs, nodeData);

View File

@@ -19,6 +19,7 @@
#include <BeastConfig.h>
#include <ripple/overlay/Overlay.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -29,7 +30,7 @@ namespace ripple {
// XXX Might allow domain for manual connections.
Json::Value doConnect (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
if (getConfig ().RUN_STANDALONE)
return "cannot connect in standalone mode";

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -26,7 +27,7 @@ Json::Value doConsensusInfo (RPC::Context& context)
Json::Value ret (Json::objectValue);
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
ret[jss::info] = context.netOps.getConsensusInfo ();
}

View File

@@ -18,12 +18,13 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
Json::Value doLedgerAccept (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
Json::Value jvResult;
if (!getConfig ().RUN_STANDALONE)

View File

@@ -20,6 +20,7 @@
#include <BeastConfig.h>
#include <ripple/app/peers/UniqueNodeList.h>
#include <ripple/overlay/Overlay.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -29,7 +30,7 @@ Json::Value doPeers (RPC::Context& context)
Json::Value jvResult (Json::objectValue);
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
jvResult[jss::peers] = getApp().overlay ().json ();
getApp().getUNL().addClusterStatus(jvResult);

View File

@@ -18,12 +18,13 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
Json::Value doStop (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
getApp().signalStop ();
return RPC::makeObjectValue (systemName () + " server stopping");

View File

@@ -19,6 +19,7 @@
#include <BeastConfig.h>
#include <ripple/app/peers/UniqueNodeList.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -28,7 +29,7 @@ namespace ripple {
// }
Json::Value doUnlAdd (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
std::string strNode = context.params.isMember (jss::node)
? context.params[jss::node].asString () : "";

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -26,7 +27,7 @@ namespace ripple {
// }
Json::Value doUnlDelete (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
if (!context.params.isMember (jss::node))
return rpcError (rpcINVALID_PARAMS);

View File

@@ -18,12 +18,13 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
Json::Value doUnlList (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
Json::Value obj (Json::objectValue);
obj[jss::unl] = getApp().getUNL ().getUnlJson ();

View File

@@ -18,13 +18,14 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
// Populate the UNL from a local validators.txt file.
Json::Value doUnlLoad (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
if (getConfig ().VALIDATORS_FILE.empty ()
|| !getApp().getUNL ().nodeLoad (getConfig ().VALIDATORS_FILE))

View File

@@ -18,13 +18,14 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
// Populate the UNL from ripple.com's validators.txt file.
Json::Value doUnlNetwork (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
getApp().getUNL ().nodeNetwork ();
return RPC::makeObjectValue ("fetching");

View File

@@ -18,12 +18,13 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
Json::Value doUnlReset (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
getApp().getUNL ().nodeReset ();
return RPC::makeObjectValue ("removing nodes");

View File

@@ -18,13 +18,14 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
// unl_score
Json::Value doUnlScore (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
getApp().getUNL ().nodeScore ();
return RPC::makeObjectValue ("scoring requested");

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <BeastConfig.h>
#include <beast/utility/make_lock.h>
namespace ripple {
@@ -26,7 +27,7 @@ namespace ripple {
// }
Json::Value doValidationSeed (RPC::Context& context)
{
auto lock = getApp().masterLock();
auto lock = beast::make_lock(getApp().getMasterMutex());
Json::Value obj (Json::objectValue);
if (!context.params.isMember (jss::secret))