Move InstanceCounter to ripple_basics

This commit is contained in:
Vinnie Falco
2013-05-30 09:37:31 -07:00
parent 827b5c4b10
commit 47e00f20fb
25 changed files with 27 additions and 42 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -13,7 +13,6 @@
#include "AccountState.h"
#include "NicknameState.h"
#include "SHAMap.h"
#include "InstanceCounter.h"
#include "LoadMonitor.h"
#include "JobQueue.h"

View File

@@ -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

View File

@@ -14,7 +14,6 @@
#include "Peer.h"
#include "CanonicalTXSet.h"
#include "TransactionEngine.h"
#include "InstanceCounter.h"
#include "LoadMonitor.h"
DEFINE_INSTANCE(LedgerConsensus);

View File

@@ -7,7 +7,6 @@
#include "TransactionMeta.h"
#include "Ledger.h"
#include "TransactionErr.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(LedgerEntrySetEntry);
DEFINE_INSTANCE(LedgerEntrySet);

View File

@@ -6,7 +6,6 @@
#include <boost/shared_ptr.hpp>
#include "InstanceCounter.h"
DEFINE_INSTANCE(LedgerProposal);

View File

@@ -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"

View File

@@ -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"

View File

@@ -10,7 +10,6 @@
#include <boost/unordered_map.hpp>
#include "HashedObject.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(SHAMap);
DEFINE_INSTANCE(SHAMapItem);

View File

@@ -3,7 +3,6 @@
#include "SerializedObject.h"
#include "LedgerFormats.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(SerializedLedgerEntry);

View File

@@ -6,7 +6,6 @@
#include <boost/ptr_container/ptr_vector.hpp>
#include "SerializedTypes.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(SerializedObject);
DEFINE_INSTANCE(SerializedArray);

View File

@@ -7,7 +7,6 @@
#include "SerializedObject.h"
#include "TransactionFormats.h"
#include "InstanceCounter.h"
#define TXN_SQL_NEW 'N'
#define TXN_SQL_CONFLICT 'C'

View File

@@ -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

View File

@@ -2,7 +2,6 @@
#define __VALIDATION__
#include "SerializedObject.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(SerializedValidation);

View File

@@ -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

View File

@@ -15,7 +15,6 @@
#include "SHAMap.h"
#include "SerializedTransaction.h"
#include "TransactionErr.h"
#include "InstanceCounter.h"
class Database;

View File

@@ -12,7 +12,6 @@
#include "SerializedLedger.h"
#include "LedgerEntrySet.h"
#include "TransactionErr.h"
#include "InstanceCounter.h"
DEFINE_INSTANCE(TransactionEngine);

View File

@@ -11,7 +11,6 @@
#include "Application.h"
#include "NetworkOPs.h"
#include "CallRPC.h"
#include "InstanceCounter.h"
#include "LoadManager.h"
#include "RPCErr.h"