Merge pull request #9022 from RandomShaper/improve-mem-class-2.1

Remove mutex-locking from non-debug memory routines (2.1)
This commit is contained in:
Rémi Verschelde 2017-06-17 12:45:12 +02:00 committed by GitHub
commit ff002ada5d

View File

@ -67,10 +67,10 @@ void *MemoryPoolStaticMalloc::_alloc(size_t p_bytes, const char *p_description)
ERR_FAIL_COND_V(p_bytes == 0, 0);
MutexLock lock(mutex);
#ifdef DEBUG_MEMORY_ENABLED
MutexLock lock(mutex);
size_t total;
#if defined(_add_overflow)
if (_add_overflow(p_bytes, sizeof(RingPtr), &total)) return NULL;
@ -176,10 +176,10 @@ void *MemoryPoolStaticMalloc::_realloc(void *p_memory, size_t p_bytes) {
return NULL;
}
MutexLock lock(mutex);
#ifdef DEBUG_MEMORY_ENABLED
MutexLock lock(mutex);
RingPtr *ringptr = (RingPtr *)p_memory;
ringptr--; /* go back an element to find the tingptr */
@ -240,10 +240,10 @@ void MemoryPoolStaticMalloc::free(void *p_ptr) {
void MemoryPoolStaticMalloc::_free(void *p_ptr) {
MutexLock lock(mutex);
#ifdef DEBUG_MEMORY_ENABLED
MutexLock lock(mutex);
if (p_ptr == 0) {
printf("**ERROR: STATIC ALLOC: Attempted free of NULL pointer.\n");
return;
@ -298,7 +298,7 @@ void MemoryPoolStaticMalloc::_free(void *p_ptr) {
total_mem -= ringptr->size;
total_pointers--;
// catch more errors
zeromem(ringptr, sizeof(RingPtr) + ringptr->size);
memset(ringptr, 0xEA, sizeof(RingPtr) + ringptr->size);
::free(ringptr); //just free that pointer
#else