Make sure that global variables are initialized lazily.
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.cpp
index e428837..7a7183b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,7 +29,11 @@ namespace
 {
 // Memory pool used to allocate new nodes. Memory used by this pool will be released when process dies
 //  or DALI library is unloaded
-Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::Node> gNodeMemoryPool;
+Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::Node>& GetNodeMemoryPool()
+{
+  static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::Node> gNodeMemoryPool;
+  return gNodeMemoryPool;
+}
 #ifdef DEBUG_ENABLED
 // keep track of nodes alive, to ensure we have 0 when the process exits or DALi library is unloaded
 int32_t gNodeCount = 0;
@@ -54,7 +58,7 @@ uint32_t Node::mNodeCounter = 0; ///< A counter to provide unique node ids, up-t
 
 Node* Node::New()
 {
-  return new(gNodeMemoryPool.AllocateRawThreadSafe()) Node;
+  return new(GetNodeMemoryPool().AllocateRawThreadSafe()) Node;
 }
 
 void Node::Delete(Node* node)
@@ -66,7 +70,7 @@ void Node::Delete(Node* node)
     node->~Node();
 
     // Mark the memory it used as free in the memory pool
-    gNodeMemoryPool.FreeThreadSafe(node);
+    GetNodeMemoryPool().FreeThreadSafe(node);
   }
   else
   {
@@ -336,7 +340,7 @@ void Node::RecursiveDisconnectFromSceneGraph(BufferIndex updateBufferIndex)
 
 uint32_t Node::GetMemoryPoolCapacity()
 {
-  return gNodeMemoryPool.GetCapacity();
+  return GetNodeMemoryPool().GetCapacity();
 }
 
 } // namespace SceneGraph