@@ -46,15 +46,23 @@ typedef struct {
4646 uint32_t pad;
4747} alloc_info_t ;
4848
49- static SingletonPtr<PlatformMutex> malloc_stats_mutex;
49+ # ifdef MBED_MEM_TRACING_ENABLED
5050static SingletonPtr<PlatformMutex> mem_trace_mutex;
51+ #endif
52+ #ifdef MBED_HEAP_STATS_ENABLED
53+ static SingletonPtr<PlatformMutex> malloc_stats_mutex;
5154static mbed_stats_heap_t heap_stats = {0 , 0 , 0 , 0 , 0 };
55+ #endif
5256
5357void mbed_stats_heap_get (mbed_stats_heap_t *stats)
5458{
59+ #ifdef MBED_HEAP_STATS_ENABLED
5560 malloc_stats_mutex->lock ();
5661 memcpy (stats, &heap_stats, sizeof (mbed_stats_heap_t ));
5762 malloc_stats_mutex->unlock ();
63+ #else
64+ memset (stats, 0 , sizeof (mbed_stats_heap_t ));
65+ #endif
5866}
5967
6068/* *****************************************************************************/
@@ -260,12 +268,12 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
260268 free (ptr);
261269 }
262270#else // #ifdef MBED_HEAP_STATS_ENABLED
263- mem_trace_mutex->lock ();
264271 new_ptr = $Super$$realloc (ptr, size);
265- mem_trace_mutex->unlock ();
266272#endif // #ifdef MBED_HEAP_STATS_ENABLED
267273#ifdef MBED_MEM_TRACING_ENABLED
274+ mem_trace_mutex->lock ();
268275 mbed_mem_trace_realloc (new_ptr, ptr, size, MBED_CALLER_ADDR ());
276+ mem_trace_mutex->unlock ();
269277#endif // #ifdef MBED_MEM_TRACING_ENABLED
270278 return new_ptr;
271279}
0 commit comments