Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions hal/common/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ typedef struct {
uint32_t pad;
} alloc_info_t;

static SingletonPtr<PlatformMutex> malloc_stats_mutex;
#ifdef MBED_MEM_TRACING_ENABLED
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};
#endif

void mbed_stats_heap_get(mbed_stats_heap_t *stats)
{
#ifdef MBED_HEAP_STATS_ENABLED
malloc_stats_mutex->lock();
memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t));
malloc_stats_mutex->unlock();
#else
memset(stats, 0, sizeof(mbed_stats_heap_t));
#endif
}

/******************************************************************************/
Expand Down Expand Up @@ -259,12 +267,12 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
free(ptr);
}
#else // #ifdef MBED_HEAP_STATS_ENABLED
mem_trace_mutex->lock();
new_ptr = $Super$$realloc(ptr, size);
mem_trace_mutex->unlock();
#endif // #ifdef MBED_HEAP_STATS_ENABLED
#ifdef MBED_MEM_TRACING_ENABLED
mem_trace_mutex->lock();
mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
mem_trace_mutex->unlock();
#endif // #ifdef MBED_MEM_TRACING_ENABLED
return new_ptr;
}
Expand Down