[HAL] Improve memory tracer

Fixed a bug and compiler warning in the memory tracer implementation.
pull/2596/head
Neil Thiessen 2016-08-31 11:46:42 -06:00 committed by GitHub
parent 9111aa4c2d
commit 6aab0606a1
1 changed files with 11 additions and 3 deletions

View File

@ -46,15 +46,23 @@ typedef struct {
uint32_t pad; uint32_t pad;
} alloc_info_t; } alloc_info_t;
static SingletonPtr<PlatformMutex> malloc_stats_mutex; #ifdef MBED_MEM_TRACING_ENABLED
static SingletonPtr<PlatformMutex> mem_trace_mutex; static SingletonPtr<PlatformMutex> mem_trace_mutex;
#endif
#ifdef MBED_HEAP_STATS_ENABLED
static SingletonPtr<PlatformMutex> malloc_stats_mutex;
static mbed_stats_heap_t heap_stats = {0, 0, 0, 0, 0}; static mbed_stats_heap_t heap_stats = {0, 0, 0, 0, 0};
#endif
void mbed_stats_heap_get(mbed_stats_heap_t *stats) void mbed_stats_heap_get(mbed_stats_heap_t *stats)
{ {
#ifdef MBED_HEAP_STATS_ENABLED
malloc_stats_mutex->lock(); malloc_stats_mutex->lock();
memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t)); memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t));
malloc_stats_mutex->unlock(); malloc_stats_mutex->unlock();
#else
memset(stats, 0, sizeof(mbed_stats_heap_t));
#endif
} }
/******************************************************************************/ /******************************************************************************/
@ -259,12 +267,12 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
free(ptr); free(ptr);
} }
#else // #ifdef MBED_HEAP_STATS_ENABLED #else // #ifdef MBED_HEAP_STATS_ENABLED
mem_trace_mutex->lock();
new_ptr = $Super$$realloc(ptr, size); new_ptr = $Super$$realloc(ptr, size);
mem_trace_mutex->unlock();
#endif // #ifdef MBED_HEAP_STATS_ENABLED #endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED #ifdef MBED_MEM_TRACING_ENABLED
mem_trace_mutex->lock();
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mem_trace_mutex->unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED #endif // #ifdef MBED_MEM_TRACING_ENABLED
return new_ptr; return new_ptr;
} }