mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 14:05:51 +00:00
Fix the crash on startup if instances are created before the instance
tracking is initialized.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "InstanceCounter.h"
|
#include "InstanceCounter.h"
|
||||||
|
|
||||||
InstanceType* InstanceType::sHeadInstance = NULL;
|
InstanceType* InstanceType::sHeadInstance = NULL;
|
||||||
|
bool InstanceType::sMultiThreaded = false;
|
||||||
|
|
||||||
std::vector<InstanceType::InstanceCount> InstanceType::getInstanceCounts(int min)
|
std::vector<InstanceType::InstanceCount> InstanceType::getInstanceCounts(int min)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ protected:
|
|||||||
|
|
||||||
InstanceType* mNextInstance;
|
InstanceType* mNextInstance;
|
||||||
static InstanceType* sHeadInstance;
|
static InstanceType* sHeadInstance;
|
||||||
|
static bool sMultiThreaded;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::pair<std::string, int> InstanceCount;
|
typedef std::pair<std::string, int> InstanceCount;
|
||||||
@@ -42,18 +43,33 @@ public:
|
|||||||
sHeadInstance = this;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void addInstance()
|
void addInstance()
|
||||||
|
{
|
||||||
|
if (sMultiThreaded)
|
||||||
{
|
{
|
||||||
mLock.lock();
|
mLock.lock();
|
||||||
++mInstances;
|
++mInstances;
|
||||||
mLock.unlock();
|
mLock.unlock();
|
||||||
}
|
}
|
||||||
|
else ++mInstances;
|
||||||
|
}
|
||||||
void decInstance()
|
void decInstance()
|
||||||
|
{
|
||||||
|
if (sMultiThreaded)
|
||||||
{
|
{
|
||||||
mLock.lock();
|
mLock.lock();
|
||||||
--mInstances;
|
--mInstances;
|
||||||
mLock.unlock();
|
mLock.unlock();
|
||||||
}
|
}
|
||||||
|
else --mInstances;
|
||||||
|
}
|
||||||
int getCount()
|
int getCount()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock(mLock);
|
boost::mutex::scoped_lock(mLock);
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ int main(int argc, char* argv[])
|
|||||||
Log::setMinSeverity(lsTRACE, true);
|
Log::setMinSeverity(lsTRACE, true);
|
||||||
else
|
else
|
||||||
Log::setMinSeverity(lsWARNING, true);
|
Log::setMinSeverity(lsWARNING, true);
|
||||||
|
InstanceType::multiThread();
|
||||||
|
|
||||||
if (vm.count("test"))
|
if (vm.count("test"))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user