Remove mutex-locking from non-debug memory routines
since the malloc() suite is nowadays thread-safe by itself (from MSVC 2010 you don't even have a non-MT runtime and for POSIX-based OSs it's mandatory by the spec. Bonus: Clear about-to-be-released blocks with a better magic number for better debugging of dangling pointers.
This commit is contained in:
parent
5f98c16d59
commit
14e30c3faa
@ -67,10 +67,10 @@ void *MemoryPoolStaticMalloc::_alloc(size_t p_bytes, const char *p_description)
|
|||||||
|
|
||||||
ERR_FAIL_COND_V(p_bytes == 0, 0);
|
ERR_FAIL_COND_V(p_bytes == 0, 0);
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
#ifdef DEBUG_MEMORY_ENABLED
|
#ifdef DEBUG_MEMORY_ENABLED
|
||||||
|
|
||||||
|
MutexLock lock(mutex);
|
||||||
|
|
||||||
size_t total;
|
size_t total;
|
||||||
#if defined(_add_overflow)
|
#if defined(_add_overflow)
|
||||||
if (_add_overflow(p_bytes, sizeof(RingPtr), &total)) return NULL;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
#ifdef DEBUG_MEMORY_ENABLED
|
#ifdef DEBUG_MEMORY_ENABLED
|
||||||
|
|
||||||
|
MutexLock lock(mutex);
|
||||||
|
|
||||||
RingPtr *ringptr = (RingPtr *)p_memory;
|
RingPtr *ringptr = (RingPtr *)p_memory;
|
||||||
ringptr--; /* go back an element to find the tingptr */
|
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) {
|
void MemoryPoolStaticMalloc::_free(void *p_ptr) {
|
||||||
|
|
||||||
MutexLock lock(mutex);
|
|
||||||
|
|
||||||
#ifdef DEBUG_MEMORY_ENABLED
|
#ifdef DEBUG_MEMORY_ENABLED
|
||||||
|
|
||||||
|
MutexLock lock(mutex);
|
||||||
|
|
||||||
if (p_ptr == 0) {
|
if (p_ptr == 0) {
|
||||||
printf("**ERROR: STATIC ALLOC: Attempted free of NULL pointer.\n");
|
printf("**ERROR: STATIC ALLOC: Attempted free of NULL pointer.\n");
|
||||||
return;
|
return;
|
||||||
@ -298,7 +298,7 @@ void MemoryPoolStaticMalloc::_free(void *p_ptr) {
|
|||||||
total_mem -= ringptr->size;
|
total_mem -= ringptr->size;
|
||||||
total_pointers--;
|
total_pointers--;
|
||||||
// catch more errors
|
// catch more errors
|
||||||
zeromem(ringptr, sizeof(RingPtr) + ringptr->size);
|
memset(ringptr, 0xEA, sizeof(RingPtr) + ringptr->size);
|
||||||
::free(ringptr); //just free that pointer
|
::free(ringptr); //just free that pointer
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user