Ver Fonte

Protect access to global g_proxy_allocators_head

Daniele Bartolini há 12 anos atrás
pai
commit
9c24bdf22d
2 ficheiros alterados com 8 adições e 0 exclusões
  1. 7 0
      engine/core/mem/ProxyAllocator.cpp
  2. 1 0
      engine/core/mem/ProxyAllocator.h

+ 7 - 0
engine/core/mem/ProxyAllocator.cpp

@@ -33,6 +33,7 @@ namespace crown
 {
 
 static ProxyAllocator* g_proxy_allocators_head = NULL;
+static Mutex g_proxy_allocators_mutex;
 
 //-----------------------------------------------------------------------------
 ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
@@ -41,6 +42,8 @@ ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 	m_total_allocated(0),
 	m_next(NULL)
 {
+	ScopedMutex sm(g_proxy_allocators_mutex);
+
 	CE_ASSERT(name != NULL, "Name must be != NULL");
 
 	if(g_proxy_allocators_head != NULL)
@@ -80,6 +83,8 @@ const char* ProxyAllocator::name() const
 //-----------------------------------------------------------------------------
 uint32_t ProxyAllocator::count()
 {
+	ScopedMutex sm(g_proxy_allocators_mutex);
+
 	const ProxyAllocator* head = g_proxy_allocators_head;
 	uint32_t count = 0;
 
@@ -95,6 +100,8 @@ uint32_t ProxyAllocator::count()
 //-----------------------------------------------------------------------------
 ProxyAllocator* ProxyAllocator::find(const char* name)
 {
+	ScopedMutex sm(g_proxy_allocators_mutex);
+
 	ProxyAllocator* head = g_proxy_allocators_head;
 
 	while (head != NULL)

+ 1 - 0
engine/core/mem/ProxyAllocator.h

@@ -29,6 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Memory.h"
 #include "Allocator.h"
+#include "ScopedMutex.h"
 
 namespace crown
 {