Commit 58c86fef by Marcus Winter

mtapi_cpp: used double-checked locking pattern in Node::GetInstance

parent 049b3b00
...@@ -198,13 +198,15 @@ bool Node::IsInitialized() { ...@@ -198,13 +198,15 @@ bool Node::IsInitialized() {
Node & Node::GetInstance() { Node & Node::GetInstance() {
#if MTAPI_CPP_AUTOMATIC_INITIALIZE #if MTAPI_CPP_AUTOMATIC_INITIALIZE
init_mutex.Lock();
if (!IsInitialized()) { if (!IsInitialized()) {
Node::Initialize( init_mutex.Lock();
MTAPI_CPP_AUTOMATIC_DOMAIN_ID, MTAPI_CPP_AUTOMATIC_NODE_ID); if (!IsInitialized()) {
atexit(Node::Finalize); Node::Initialize(
MTAPI_CPP_AUTOMATIC_DOMAIN_ID, MTAPI_CPP_AUTOMATIC_NODE_ID);
atexit(Node::Finalize);
}
init_mutex.Unlock();
} }
init_mutex.Unlock();
return *node_instance; return *node_instance;
#else #else
if (IsInitialized()) { if (IsInitialized()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment