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"
|
||||
|
||||
InstanceType* InstanceType::sHeadInstance = NULL;
|
||||
bool InstanceType::sMultiThreaded = false;
|
||||
|
||||
std::vector<InstanceType::InstanceCount> InstanceType::getInstanceCounts(int min)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ protected:
|
||||
|
||||
InstanceType* mNextInstance;
|
||||
static InstanceType* sHeadInstance;
|
||||
static bool sMultiThreaded;
|
||||
|
||||
public:
|
||||
typedef std::pair<std::string, int> InstanceCount;
|
||||
@@ -42,18 +43,33 @@ public:
|
||||
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()
|
||||
{
|
||||
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(mLock);
|
||||
|
||||
@@ -145,6 +145,7 @@ int main(int argc, char* argv[])
|
||||
Log::setMinSeverity(lsTRACE, true);
|
||||
else
|
||||
Log::setMinSeverity(lsWARNING, true);
|
||||
InstanceType::multiThread();
|
||||
|
||||
if (vm.count("test"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user