mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Move InstanceCounter to ripple_basics
This commit is contained in:
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "modules/ripple_main/misc/ripple_HashValue.h"
|
||||
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
|
||||
// VFALCO: TODO, Move this to someplace sensible!!
|
||||
// Adapter to furnish uptime information to KeyCache via UptimeTimer singleton
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
InstanceType* InstanceType::sHeadInstance = NULL;
|
||||
bool InstanceType::sMultiThreaded = false;
|
||||
|
||||
std::vector<InstanceType::InstanceCount> InstanceType::getInstanceCounts(int min)
|
||||
{
|
||||
std::vector<InstanceCount> ret;
|
||||
for (InstanceType* i = sHeadInstance; i != NULL; i = i->mNextInstance)
|
||||
{
|
||||
int c = i->getCount();
|
||||
if (c >= min)
|
||||
ret.push_back(InstanceCount(i->getName(), c));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
#ifndef INSTANCE_COUNTER__H
|
||||
#define INSTANCE_COUNTER__H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#define DEFINE_INSTANCE(x) \
|
||||
extern InstanceType IT_##x; \
|
||||
class Instance_##x : private Instance \
|
||||
{ \
|
||||
protected: \
|
||||
Instance_##x() : Instance(IT_##x) { ; } \
|
||||
Instance_##x(const Instance_##x &) : \
|
||||
Instance(IT_##x) { ; } \
|
||||
Instance_##x& operator=(const Instance_##x&) \
|
||||
{ return *this; } \
|
||||
}
|
||||
|
||||
#define DECLARE_INSTANCE(x) \
|
||||
InstanceType IT_##x(#x);
|
||||
|
||||
#define IS_INSTANCE(x) Instance_##x
|
||||
|
||||
class InstanceType
|
||||
{
|
||||
protected:
|
||||
int mInstances;
|
||||
std::string mName;
|
||||
boost::mutex mLock;
|
||||
|
||||
InstanceType* mNextInstance;
|
||||
static InstanceType* sHeadInstance;
|
||||
static bool sMultiThreaded;
|
||||
|
||||
public:
|
||||
typedef std::pair<std::string, int> InstanceCount;
|
||||
|
||||
InstanceType(const char *n) : mInstances(0), mName(n)
|
||||
{
|
||||
mNextInstance = sHeadInstance;
|
||||
sHeadInstance = this;
|
||||
}
|
||||
|
||||
static void multiThread()
|
||||
{
|
||||
// We can support global objects and multi-threaded code, but not both
|
||||
// at the same time. Switch to multi-threaded.
|
||||
sMultiThreaded = true;
|
||||
}
|
||||
|
||||
static void shutdown()
|
||||
{
|
||||
sMultiThreaded = false;
|
||||
}
|
||||
|
||||
static bool isMultiThread()
|
||||
{
|
||||
return sMultiThreaded;
|
||||
}
|
||||
|
||||
void addInstance()
|
||||
{
|
||||
if (sMultiThreaded)
|
||||
{
|
||||
mLock.lock();
|
||||
++mInstances;
|
||||
mLock.unlock();
|
||||
}
|
||||
else ++mInstances;
|
||||
}
|
||||
void decInstance()
|
||||
{
|
||||
if (sMultiThreaded)
|
||||
{
|
||||
mLock.lock();
|
||||
--mInstances;
|
||||
mLock.unlock();
|
||||
}
|
||||
else --mInstances;
|
||||
}
|
||||
int getCount()
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
return mInstances;
|
||||
}
|
||||
const std::string& getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
static std::vector<InstanceCount> getInstanceCounts(int min = 1);
|
||||
};
|
||||
|
||||
class Instance
|
||||
{
|
||||
protected:
|
||||
static bool running;
|
||||
InstanceType& mType;
|
||||
|
||||
public:
|
||||
Instance(InstanceType& t) : mType(t) { mType.addInstance(); }
|
||||
~Instance() { if (running) mType.decInstance(); }
|
||||
static void shutdown() { running = false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "AccountState.h"
|
||||
#include "NicknameState.h"
|
||||
#include "SHAMap.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "LoadMonitor.h"
|
||||
#include "JobQueue.h"
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "Ledger.h"
|
||||
#include "Peer.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "ripple.pb.h"
|
||||
|
||||
// How long before we try again to acquire the same ledger
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "Peer.h"
|
||||
#include "CanonicalTXSet.h"
|
||||
#include "TransactionEngine.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "LoadMonitor.h"
|
||||
|
||||
DEFINE_INSTANCE(LedgerConsensus);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "TransactionMeta.h"
|
||||
#include "Ledger.h"
|
||||
#include "TransactionErr.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(LedgerEntrySetEntry);
|
||||
DEFINE_INSTANCE(LedgerEntrySet);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(LedgerProposal);
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "PackedMessage.h"
|
||||
#include "Ledger.h"
|
||||
#include "Transaction.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "JobQueue.h"
|
||||
#include "ProofOfWork.h"
|
||||
#include "LoadManager.h"
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "RPCErr.h"
|
||||
#include "AccountState.h"
|
||||
#include "NicknameState.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "Offer.h"
|
||||
#include "PFRequest.h"
|
||||
#include "ProofOfWork.h"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include "HashedObject.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(SHAMap);
|
||||
DEFINE_INSTANCE(SHAMapItem);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "SerializedObject.h"
|
||||
#include "LedgerFormats.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(SerializedLedgerEntry);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
|
||||
#include "SerializedTypes.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(SerializedObject);
|
||||
DEFINE_INSTANCE(SerializedArray);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "SerializedObject.h"
|
||||
#include "TransactionFormats.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
#define TXN_SQL_NEW 'N'
|
||||
#define TXN_SQL_CONFLICT 'C'
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
// CAUTION: Do not create a vector (or similar container) of any object derived from
|
||||
// SerializedType. Use Boost ptr_* containers. The copy assignment operator of
|
||||
// SerializedType has semantics that will cause contained types to change their names
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define __VALIDATION__
|
||||
|
||||
#include "SerializedObject.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(SerializedValidation);
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
DEFINE_INSTANCE(Suppression);
|
||||
|
||||
#define SF_RELAYED 0x01 // Has already been relayed to other nodes
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "SHAMap.h"
|
||||
#include "SerializedTransaction.h"
|
||||
#include "TransactionErr.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
class Database;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "SerializedLedger.h"
|
||||
#include "LedgerEntrySet.h"
|
||||
#include "TransactionErr.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
|
||||
DEFINE_INSTANCE(TransactionEngine);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "Application.h"
|
||||
#include "NetworkOPs.h"
|
||||
#include "CallRPC.h"
|
||||
#include "InstanceCounter.h"
|
||||
#include "LoadManager.h"
|
||||
#include "RPCErr.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user