Except when interacting with boost, use std::function and std::bind

when C++11 is available. See: http://stackoverflow.com/questions/14617835
This commit is contained in:
JoelKatz
2013-03-16 03:27:43 -07:00
parent 606dff758c
commit b9456c8fd7
17 changed files with 60 additions and 48 deletions

View File

@@ -52,7 +52,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
{
mWritePending = true;
theApp->getJobQueue().addJob(jtWRITE, "HashedObject::store",
boost::bind(&HashedObjectStore::bulkWrite, this));
BIND_TYPE(&HashedObjectStore::bulkWrite, this));
}
}
// else

View File

@@ -97,7 +97,7 @@ bool Job::operator<=(const Job& j) const
return mJobIndex <= j.mJobIndex;
}
void JobQueue::addJob(JobType type, const std::string& name, const boost::function<void(Job&)>& jobFunc)
void JobQueue::addJob(JobType type, const std::string& name, const FUNCTION_TYPE<void(Job&)>& jobFunc)
{
assert(type != jtINVALID);
@@ -246,7 +246,7 @@ void JobQueue::setThreadCount(int c)
while (mThreadCount < c)
{
++mThreadCount;
boost::thread(boost::bind(&JobQueue::threadEntry, this)).detach();
boost::thread(BIND_TYPE(&JobQueue::threadEntry, this)).detach();
}
while (mThreadCount > c)
{

View File

@@ -7,8 +7,8 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/function.hpp>
#include <boost/make_shared.hpp>
#include <boost/ref.hpp>
#include "../json/value.h"
@@ -52,7 +52,7 @@ class Job
protected:
JobType mType;
uint64 mJobIndex;
boost::function<void(Job&)> mJob;
FUNCTION_TYPE<void(Job&)> mJob;
LoadEvent::pointer mLoadMonitor;
std::string mName;
@@ -63,7 +63,7 @@ public:
Job(JobType type, uint64 index) : mType(type), mJobIndex(index)
{ ; }
Job(JobType type, const std::string& name, uint64 index, LoadMonitor& lm, const boost::function<void(Job&)>& job)
Job(JobType type, const std::string& name, uint64 index, LoadMonitor& lm, const FUNCTION_TYPE<void(Job&)>& job)
: mType(type), mJobIndex(index), mJob(job), mName(name)
{
mLoadMonitor = boost::make_shared<LoadEvent>(boost::ref(lm), name, false);
@@ -102,7 +102,7 @@ public:
JobQueue();
void addJob(JobType type, const std::string& name, const boost::function<void(Job&)>& job);
void addJob(JobType type, const std::string& name, const FUNCTION_TYPE<void(Job&)>& job);
int getJobCount(JobType t); // Jobs waiting at this priority
int getJobCountTotal(JobType t); // Jobs waiting plus running at this priority

View File

@@ -1540,7 +1540,7 @@ void Ledger::pendSave(bool fromConsensus)
theApp->getJobQueue().addJob(fromConsensus ? jtPUBLEDGER : jtPUBOLDLEDGER,
fromConsensus ? "Ledger::pendSave" : "Ledger::pendOldSave",
boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), _1, fromConsensus));
BIND_TYPE(&Ledger::saveAcceptedLedger, shared_from_this(), P_1, fromConsensus));
}

View File

@@ -3,7 +3,6 @@
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#include "Application.h"
#include "Log.h"
@@ -72,14 +71,14 @@ void PeerSet::TimerEntry(boost::weak_ptr<PeerSet> wptr, const boost::system::err
{
if (result == boost::asio::error::operation_aborted)
return;
theApp->getJobQueue().addJob(jtLEDGER_DATA, "timerEntry",
boost::bind(&PeerSet::TimerJobEntry, _1, wptr));
}
void PeerSet::TimerJobEntry(Job&, boost::weak_ptr<PeerSet> wptr)
{
boost::shared_ptr<PeerSet> ptr = wptr.lock();
if (ptr)
theApp->getJobQueue().addJob(jtLEDGER_DATA, "timerEntry",
BIND_TYPE(&PeerSet::TimerJobEntry, P_1, ptr));
}
void PeerSet::TimerJobEntry(Job&, boost::shared_ptr<PeerSet> ptr)
{
ptr->invokeOnTimer();
}
@@ -254,7 +253,7 @@ void LedgerAcquire::done()
assert(isComplete() || isFailed());
std::vector< boost::function<void (LedgerAcquire::pointer)> > triggers;
std::vector< FUNCTION_TYPE<void (LedgerAcquire::pointer)> > triggers;
{
boost::recursive_mutex::scoped_lock sl(mLock);
triggers.swap(mOnComplete);
@@ -275,7 +274,7 @@ void LedgerAcquire::done()
triggers[i](shared_from_this());
}
bool LedgerAcquire::addOnComplete(boost::function<void (LedgerAcquire::pointer)> trigger)
bool LedgerAcquire::addOnComplete(FUNCTION_TYPE<void (LedgerAcquire::pointer)> trigger)
{
boost::recursive_mutex::scoped_lock sl(mLock);
if (isDone())

View File

@@ -75,7 +75,7 @@ protected:
private:
static void TimerEntry(boost::weak_ptr<PeerSet>, const boost::system::error_code& result);
static void TimerJobEntry(Job&, boost::weak_ptr<PeerSet>);
static void TimerJobEntry(Job&, boost::shared_ptr<PeerSet>);
};
class LedgerAcquire :
@@ -91,7 +91,7 @@ protected:
std::set<SHAMapNode> mRecentTXNodes;
std::set<SHAMapNode> mRecentASNodes;
std::vector< boost::function<void (LedgerAcquire::pointer)> > mOnComplete;
std::vector< FUNCTION_TYPE<void (LedgerAcquire::pointer)> > mOnComplete;
void done();
void onTimer(bool progress);
@@ -112,7 +112,7 @@ public:
void abort() { mAborted = true; }
bool setAccept() { if (mAccept) return false; mAccept = true; return true; }
bool addOnComplete(boost::function<void (LedgerAcquire::pointer)>);
bool addOnComplete(FUNCTION_TYPE<void (LedgerAcquire::pointer)>);
bool takeBase(const std::string& data);
bool takeTxNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data,

View File

@@ -529,7 +529,7 @@ TER LedgerEntrySet::dirAdd(
uint64& uNodeDir,
const uint256& uRootIndex,
const uint256& uLedgerIndex,
boost::function<void (SLE::ref)> fDescriber)
FUNCTION_TYPE<void (SLE::ref)> fDescriber)
{
cLog(lsDEBUG)
<< boost::str(boost::format("dirAdd: uRootIndex=%s uLedgerIndex=%s")
@@ -1195,7 +1195,7 @@ TER LedgerEntrySet::trustCreate(
uLowNode,
Ledger::getOwnerDirIndex(uLowAccountID),
sleRippleState->getIndex(),
boost::bind(&Ledger::ownerDirDescriber, _1, uLowAccountID));
BIND_TYPE(&Ledger::ownerDirDescriber, P_1, uLowAccountID));
if (tesSUCCESS == terResult)
{
@@ -1203,7 +1203,7 @@ TER LedgerEntrySet::trustCreate(
uHighNode,
Ledger::getOwnerDirIndex(uHighAccountID),
sleRippleState->getIndex(),
boost::bind(&Ledger::ownerDirDescriber, _1, uHighAccountID));
BIND_TYPE(&Ledger::ownerDirDescriber, P_1, uHighAccountID));
}
if (tesSUCCESS == terResult)

View File

@@ -2,7 +2,6 @@
#define __LEDGERENTRYSET__
#include <boost/unordered_map.hpp>
#include <boost/function.hpp>
#include "SerializedLedger.h"
#include "TransactionMeta.h"
@@ -106,7 +105,7 @@ public:
uint64& uNodeDir, // Node of entry.
const uint256& uRootIndex,
const uint256& uLedgerIndex,
boost::function<void (SLE::ref)> fDescriber);
FUNCTION_TYPE<void (SLE::ref)> fDescriber);
TER dirDelete(
const bool bKeepRoot,

View File

@@ -197,7 +197,7 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
{
cLog(lsTRACE) << "Ledger hash found in database";
theApp->getJobQueue().addJob(jtPUBOLDLEDGER, "LedgerMaster::asyncAccept",
boost::bind(&LedgerMaster::asyncAccept, this, ledger));
BIND_TYPE(&LedgerMaster::asyncAccept, this, ledger));
return true;
}
@@ -224,7 +224,7 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
mMissingSeq = ledgerSeq;
if (mMissingLedger->setAccept())
{
if (!mMissingLedger->addOnComplete(boost::bind(&LedgerMaster::missingAcquireComplete, this, _1)))
if (!mMissingLedger->addOnComplete(BIND_TYPE(&LedgerMaster::missingAcquireComplete, this, P_1)))
theApp->getIOService().post(boost::bind(&LedgerMaster::missingAcquireComplete, this, mMissingLedger));
}
@@ -554,7 +554,7 @@ void LedgerMaster::tryPublish()
theApp->getOPs().clearNeedNetworkLedger();
mPubThread = true;
theApp->getJobQueue().addJob(jtPUBLEDGER, "Ledger::pubThread",
boost::bind(&LedgerMaster::pubThread, this));
BIND_TYPE(&LedgerMaster::pubThread, this));
}
}

View File

@@ -18,7 +18,7 @@
class LedgerMaster
{
public:
typedef boost::function<void(Ledger::ref)> callback;
typedef FUNCTION_TYPE<void(Ledger::ref)> callback;
protected:
boost::recursive_mutex mLock;

View File

@@ -1,7 +1,6 @@
#include "NetworkOPs.h"
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include "utils.h"
@@ -1380,7 +1379,7 @@ void NetworkOPs::reportFeeChange()
(theApp->getFeeTrack().getLoadFactor() == mLastLoadFactor))
return;
theApp->getJobQueue().addJob(jtCLIENT, "reportFeeChange->pubServer", boost::bind(&NetworkOPs::pubServer, this));
theApp->getJobQueue().addJob(jtCLIENT, "reportFeeChange->pubServer", BIND_TYPE(&NetworkOPs::pubServer, this));
}
Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terResult, bool bValidated,

View File

@@ -534,7 +534,7 @@ TER OfferCreateTransactor::doApply()
// Add offer to owner's directory.
terResult = lesActive.dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
BIND_TYPE(&Ledger::qualityDirDescriber, P_1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
@@ -555,7 +555,7 @@ TER OfferCreateTransactor::doApply()
// Add offer to order book.
terResult = lesActive.dirAdd(uBookNode, uDirectory, uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
BIND_TYPE(&Ledger::qualityDirDescriber, P_1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
}

View File

@@ -870,7 +870,7 @@ void Peer::recvTransaction(ripple::TMTransaction& packet)
}
theApp->getJobQueue().addJob(jtTRANSACTION, "recvTransction->checkTransaction",
boost::bind(&checkTransaction, _1, flags, stx, boost::weak_ptr<Peer>(shared_from_this())));
BIND_TYPE(&checkTransaction, P_1, flags, stx, boost::weak_ptr<Peer>(shared_from_this())));
#ifndef TRUST_NETWORK
}
@@ -931,7 +931,7 @@ static void checkPropose(Job& job, boost::shared_ptr<ripple::TMProposeSet> packe
if (isTrusted)
{
theApp->getJobQueue().addJob(jtPROPOSAL_t, "trustedProposal",
boost::bind(&NetworkOPs::processTrustedProposal, &theApp->getOPs(),
BIND_TYPE(&NetworkOPs::processTrustedProposal, &theApp->getOPs(),
proposal, packet, nodePublic, prevLedger, sigGood));
}
else if (sigGood && (prevLedger == consensusLCL))
@@ -1002,7 +1002,7 @@ void Peer::recvPropose(const boost::shared_ptr<ripple::TMProposeSet>& packet)
set.proposeseq(), proposeHash, set.closetime(), signerPublic, suppression);
theApp->getJobQueue().addJob(isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut, "recvPropose->checkPropose",
boost::bind(&checkPropose, _1, packet, proposal, consensusLCL,
BIND_TYPE(&checkPropose, P_1, packet, proposal, consensusLCL,
mNodePublic, boost::weak_ptr<Peer>(shared_from_this())));
}
@@ -1078,7 +1078,7 @@ void Peer::recvValidation(const boost::shared_ptr<ripple::TMValidation>& packet)
bool isTrusted = theApp->getUNL().nodeInUNL(val->getSignerPublic());
theApp->getJobQueue().addJob(isTrusted ? jtVALIDATION_t : jtVALIDATION_ut, "recvValidation->checkValidation",
boost::bind(&checkValidation, _1, val, signingHash, isTrusted, packet,
BIND_TYPE(&checkValidation, P_1, val, signingHash, isTrusted, packet,
boost::weak_ptr<Peer>(shared_from_this())));
}
#ifndef TRUST_NETWORK
@@ -1315,7 +1315,7 @@ void Peer::recvProofWork(ripple::TMProofWork& packet)
}
theApp->getJobQueue().addJob(jtPROOFWORK, "recvProof->doProof",
boost::bind(&Peer::doProofOfWork, _1, boost::weak_ptr<Peer>(shared_from_this()), pow));
BIND_TYPE(&Peer::doProofOfWork, P_1, boost::weak_ptr<Peer>(shared_from_this()), pow));
return;
}
@@ -1666,8 +1666,8 @@ void Peer::recvLedger(const boost::shared_ptr<ripple::TMLedgerData>& packet_ptr)
}
theApp->getJobQueue().addJob(jtLEDGER_DATA, "gotLedgerData",
boost::bind(&LedgerAcquireMaster::gotLedgerData, &theApp->getMasterLedgerAcquire(),
_1, packet_ptr, boost::weak_ptr<Peer>(shared_from_this())));
BIND_TYPE(&LedgerAcquireMaster::gotLedgerData, &theApp->getMasterLedgerAcquire(),
P_1, packet_ptr, boost::weak_ptr<Peer>(shared_from_this())));
}
bool Peer::hasLedger(const uint256& hash) const

View File

@@ -21,7 +21,7 @@ class TXQEntry
public:
typedef boost::shared_ptr<TXQEntry> pointer;
typedef const boost::shared_ptr<TXQEntry>& ref;
typedef boost::function<void (Transaction::pointer, TER)> stCallback; // must complete immediately
typedef FUNCTION_TYPE<void (Transaction::pointer, TER)> stCallback; // must complete immediately
protected:
Transaction::pointer mTxn;

View File

@@ -297,7 +297,7 @@ void ValidationCollection::condWrite()
return;
mWriting = true;
theApp->getJobQueue().addJob(jtWRITE, "ValidationCollection::doWrite",
boost::bind(&ValidationCollection::doWrite, this, _1));
BIND_TYPE(&ValidationCollection::doWrite, this, P_1));
}
void ValidationCollection::doWrite(Job&)

View File

@@ -153,13 +153,13 @@ public:
// Must be done without holding the websocket send lock
theApp->getJobQueue().addJob(jtCLIENT, "WSClient::destroy",
boost::bind(&WSConnection<endpoint_type>::destroy, ptr));
BIND_TYPE(&WSConnection<endpoint_type>::destroy, ptr));
}
void on_message(connection_ptr cpClient, message_ptr mpMessage)
{
theApp->getJobQueue().addJob(jtCLIENT, "WSClient::command",
boost::bind(&WSServerHandler<endpoint_type>::do_message, this, _1, cpClient, mpMessage));
BIND_TYPE(&WSServerHandler<endpoint_type>::do_message, this, P_1, cpClient, mpMessage));
}
void do_message(Job& job, connection_ptr cpClient, message_ptr mpMessage)

View File

@@ -289,13 +289,28 @@ bool parseUrl(const std::string& strUrl, std::string& strScheme, std::string& st
#if (!defined(FORCE_NO_C11X) && (__cplusplus > 201100L)) || defined(FORCE_C11X)
#define C11X
#define UPTR_T std::unique_ptr
#define MOVE_P(p) std::move(p)
#include <functional>
#define UPTR_T std::unique_ptr
#define MOVE_P(p) std::move(p)
#define BIND_TYPE std::bind
#define FUNCTION_TYPE std::function
#define P_1 std::placeholders::_1
#define P_2 std::placeholders::_2
#define P_3 std::placeholders::_3
#define P_4 std::placeholders::_4
#else
#define UPTR_T std::auto_ptr
#define MOVE_P(p) (p)
#include <boost/bind.hpp>
#include <boost/function.hpp>
#define UPTR_T std::auto_ptr
#define MOVE_P(p) (p)
#define BIND_TYPE boost::bind
#define FUNCTION_TYPE boost::function
#define P_1 _1
#define P_2 _2
#define P_3 _3
#define P_4 _4
#endif