mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix the crash on startup if instances are created before the instance
tracking is initialized.
This commit is contained in:
@@ -32,6 +32,7 @@ protected:
|
||||
|
||||
InstanceType* mNextInstance;
|
||||
static InstanceType* sHeadInstance;
|
||||
static bool sMultiThreaded;
|
||||
|
||||
public:
|
||||
typedef std::pair<std::string, int> InstanceCount;
|
||||
@@ -42,17 +43,32 @@ 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()
|
||||
{
|
||||
mLock.lock();
|
||||
++mInstances;
|
||||
mLock.unlock();
|
||||
if (sMultiThreaded)
|
||||
{
|
||||
mLock.lock();
|
||||
++mInstances;
|
||||
mLock.unlock();
|
||||
}
|
||||
else ++mInstances;
|
||||
}
|
||||
void decInstance()
|
||||
{
|
||||
mLock.lock();
|
||||
--mInstances;
|
||||
mLock.unlock();
|
||||
if (sMultiThreaded)
|
||||
{
|
||||
mLock.lock();
|
||||
--mInstances;
|
||||
mLock.unlock();
|
||||
}
|
||||
else --mInstances;
|
||||
}
|
||||
int getCount()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user