mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 /* mbed Microcontroller Library
dkato 0:f782d9c66c49 2 * Copyright (c) 2006-2016 ARM Limited
dkato 0:f782d9c66c49 3 *
dkato 0:f782d9c66c49 4 * Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 5 * you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 6 * You may obtain a copy of the License at
dkato 0:f782d9c66c49 7 *
dkato 0:f782d9c66c49 8 * http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 9 *
dkato 0:f782d9c66c49 10 * Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 11 * distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 13 * See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 14 * limitations under the License.
dkato 0:f782d9c66c49 15 */
dkato 0:f782d9c66c49 16
dkato 0:f782d9c66c49 17 #include "platform/mbed_mem_trace.h"
dkato 0:f782d9c66c49 18 #include "platform/mbed_stats.h"
dkato 0:f782d9c66c49 19 #include "platform/mbed_toolchain.h"
dkato 0:f782d9c66c49 20 #include "platform/SingletonPtr.h"
dkato 0:f782d9c66c49 21 #include "platform/PlatformMutex.h"
dkato 0:f782d9c66c49 22 #include <stddef.h>
dkato 0:f782d9c66c49 23 #include <stdio.h>
dkato 0:f782d9c66c49 24 #include <string.h>
dkato 0:f782d9c66c49 25 #include <stdlib.h>
dkato 0:f782d9c66c49 26
dkato 0:f782d9c66c49 27 /* There are two memory tracers in mbed OS:
dkato 0:f782d9c66c49 28
dkato 0:f782d9c66c49 29 - the first can be used to detect the maximum heap usage at runtime. It is
dkato 0:f782d9c66c49 30 activated by defining the MBED_HEAP_STATS_ENABLED macro.
dkato 0:f782d9c66c49 31 - the second can be used to trace each memory call by automatically invoking
dkato 0:f782d9c66c49 32 a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is
dkato 0:f782d9c66c49 33 activated by defining the MBED_MEM_TRACING_ENABLED macro.
dkato 0:f782d9c66c49 34
dkato 0:f782d9c66c49 35 Both tracers can be activated and deactivated in any combination. If both tracers
dkato 0:f782d9c66c49 36 are active, the second one (MBED_MEM_TRACING_ENABLED) will trace the first one's
dkato 0:f782d9c66c49 37 (MBED_HEAP_STATS_ENABLED) memory calls.*/
dkato 0:f782d9c66c49 38
dkato 0:f782d9c66c49 39 /******************************************************************************/
dkato 0:f782d9c66c49 40 /* Implementation of the runtime max heap usage checker */
dkato 0:f782d9c66c49 41 /******************************************************************************/
dkato 0:f782d9c66c49 42
dkato 0:f782d9c66c49 43 /* Size must be a multiple of 8 to keep alignment */
dkato 0:f782d9c66c49 44 typedef struct {
dkato 0:f782d9c66c49 45 uint32_t size;
dkato 0:f782d9c66c49 46 uint32_t pad;
dkato 0:f782d9c66c49 47 } alloc_info_t;
dkato 0:f782d9c66c49 48
dkato 0:f782d9c66c49 49 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 50 static SingletonPtr<PlatformMutex> mem_trace_mutex;
dkato 0:f782d9c66c49 51 #endif
dkato 0:f782d9c66c49 52 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 53 static SingletonPtr<PlatformMutex> malloc_stats_mutex;
dkato 0:f782d9c66c49 54 static mbed_stats_heap_t heap_stats = {0, 0, 0, 0, 0};
dkato 0:f782d9c66c49 55 #endif
dkato 0:f782d9c66c49 56
dkato 0:f782d9c66c49 57 void mbed_stats_heap_get(mbed_stats_heap_t *stats)
dkato 0:f782d9c66c49 58 {
dkato 0:f782d9c66c49 59 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 60 extern uint32_t mbed_heap_size;
dkato 0:f782d9c66c49 61 heap_stats.reserved_size = mbed_heap_size;
dkato 0:f782d9c66c49 62
dkato 0:f782d9c66c49 63 malloc_stats_mutex->lock();
dkato 0:f782d9c66c49 64 memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t));
dkato 0:f782d9c66c49 65 malloc_stats_mutex->unlock();
dkato 0:f782d9c66c49 66 #else
dkato 0:f782d9c66c49 67 memset(stats, 0, sizeof(mbed_stats_heap_t));
dkato 0:f782d9c66c49 68 #endif
dkato 0:f782d9c66c49 69 }
dkato 0:f782d9c66c49 70
dkato 0:f782d9c66c49 71 /******************************************************************************/
dkato 0:f782d9c66c49 72 /* GCC memory allocation wrappers */
dkato 0:f782d9c66c49 73 /******************************************************************************/
dkato 0:f782d9c66c49 74
dkato 0:f782d9c66c49 75 #if defined(TOOLCHAIN_GCC)
dkato 0:f782d9c66c49 76
dkato 0:f782d9c66c49 77 #ifdef FEATURE_UVISOR
dkato 0:f782d9c66c49 78 #include "uvisor-lib/uvisor-lib.h"
dkato 0:f782d9c66c49 79 #endif/* FEATURE_UVISOR */
dkato 0:f782d9c66c49 80
dkato 0:f782d9c66c49 81 extern "C" {
dkato 0:f782d9c66c49 82 void * __real__malloc_r(struct _reent * r, size_t size);
dkato 0:f782d9c66c49 83 void * __real__realloc_r(struct _reent * r, void * ptr, size_t size);
dkato 0:f782d9c66c49 84 void __real__free_r(struct _reent * r, void * ptr);
dkato 0:f782d9c66c49 85 void* __real__calloc_r(struct _reent * r, size_t nmemb, size_t size);
dkato 0:f782d9c66c49 86 }
dkato 0:f782d9c66c49 87
dkato 0:f782d9c66c49 88 // TODO: memory tracing doesn't work with uVisor enabled.
dkato 0:f782d9c66c49 89 #if !defined(FEATURE_UVISOR)
dkato 0:f782d9c66c49 90
dkato 0:f782d9c66c49 91 extern "C" void * __wrap__malloc_r(struct _reent * r, size_t size) {
dkato 0:f782d9c66c49 92 void *ptr = NULL;
dkato 0:f782d9c66c49 93 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 94 malloc_stats_mutex->lock();
dkato 0:f782d9c66c49 95 alloc_info_t *alloc_info = (alloc_info_t*)__real__malloc_r(r, size + sizeof(alloc_info_t));
dkato 0:f782d9c66c49 96 if (alloc_info != NULL) {
dkato 0:f782d9c66c49 97 alloc_info->size = size;
dkato 0:f782d9c66c49 98 ptr = (void*)(alloc_info + 1);
dkato 0:f782d9c66c49 99 heap_stats.current_size += size;
dkato 0:f782d9c66c49 100 heap_stats.total_size += size;
dkato 0:f782d9c66c49 101 heap_stats.alloc_cnt += 1;
dkato 0:f782d9c66c49 102 if (heap_stats.current_size > heap_stats.max_size) {
dkato 0:f782d9c66c49 103 heap_stats.max_size = heap_stats.current_size;
dkato 0:f782d9c66c49 104 }
dkato 0:f782d9c66c49 105 } else {
dkato 0:f782d9c66c49 106 heap_stats.alloc_fail_cnt += 1;
dkato 0:f782d9c66c49 107 }
dkato 0:f782d9c66c49 108 malloc_stats_mutex->unlock();
dkato 0:f782d9c66c49 109 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 110 ptr = __real__malloc_r(r, size);
dkato 0:f782d9c66c49 111 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 112 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 113 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 114 mbed_mem_trace_malloc(ptr, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 115 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 116 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 117 return ptr;
dkato 0:f782d9c66c49 118 }
dkato 0:f782d9c66c49 119
dkato 0:f782d9c66c49 120 extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size) {
dkato 0:f782d9c66c49 121 void *new_ptr = NULL;
dkato 0:f782d9c66c49 122 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 123 // Implement realloc_r with malloc and free.
dkato 0:f782d9c66c49 124 // The function realloc_r can't be used here directly since
dkato 0:f782d9c66c49 125 // it can call into __wrap__malloc_r (returns ptr + 4) or
dkato 0:f782d9c66c49 126 // resize memory directly (returns ptr + 0).
dkato 0:f782d9c66c49 127
dkato 0:f782d9c66c49 128 // Note - no lock needed since malloc and free are thread safe
dkato 0:f782d9c66c49 129
dkato 0:f782d9c66c49 130 // Get old size
dkato 0:f782d9c66c49 131 uint32_t old_size = 0;
dkato 0:f782d9c66c49 132 if (ptr != NULL) {
dkato 0:f782d9c66c49 133 alloc_info_t *alloc_info = ((alloc_info_t*)ptr) - 1;
dkato 0:f782d9c66c49 134 old_size = alloc_info->size;
dkato 0:f782d9c66c49 135 }
dkato 0:f782d9c66c49 136
dkato 0:f782d9c66c49 137 // Allocate space
dkato 0:f782d9c66c49 138 if (size != 0) {
dkato 0:f782d9c66c49 139 new_ptr = malloc(size);
dkato 0:f782d9c66c49 140 }
dkato 0:f782d9c66c49 141
dkato 0:f782d9c66c49 142 // If the new buffer has been allocated copy the data to it
dkato 0:f782d9c66c49 143 // and free the old buffer
dkato 0:f782d9c66c49 144 if (new_ptr != NULL) {
dkato 0:f782d9c66c49 145 uint32_t copy_size = (old_size < size) ? old_size : size;
dkato 0:f782d9c66c49 146 memcpy(new_ptr, (void*)ptr, copy_size);
dkato 0:f782d9c66c49 147 free(ptr);
dkato 0:f782d9c66c49 148 }
dkato 0:f782d9c66c49 149 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 150 new_ptr = __real__realloc_r(r, ptr, size);
dkato 0:f782d9c66c49 151 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 152 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 153 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 154 mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 155 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 156 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 157 return new_ptr;
dkato 0:f782d9c66c49 158 }
dkato 0:f782d9c66c49 159
dkato 0:f782d9c66c49 160 extern "C" void __wrap__free_r(struct _reent * r, void * ptr) {
dkato 0:f782d9c66c49 161 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 162 malloc_stats_mutex->lock();
dkato 0:f782d9c66c49 163 alloc_info_t *alloc_info = NULL;
dkato 0:f782d9c66c49 164 if (ptr != NULL) {
dkato 0:f782d9c66c49 165 alloc_info = ((alloc_info_t*)ptr) - 1;
dkato 0:f782d9c66c49 166 heap_stats.current_size -= alloc_info->size;
dkato 0:f782d9c66c49 167 heap_stats.alloc_cnt -= 1;
dkato 0:f782d9c66c49 168 }
dkato 0:f782d9c66c49 169 __real__free_r(r, (void*)alloc_info);
dkato 0:f782d9c66c49 170 malloc_stats_mutex->unlock();
dkato 0:f782d9c66c49 171 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 172 __real__free_r(r, ptr);
dkato 0:f782d9c66c49 173 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 174 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 175 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 176 mbed_mem_trace_free(ptr, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 177 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 178 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 179 }
dkato 0:f782d9c66c49 180
dkato 0:f782d9c66c49 181 #endif // if !defined(FEATURE_UVISOR)
dkato 0:f782d9c66c49 182
dkato 0:f782d9c66c49 183 extern "C" void * __wrap__calloc_r(struct _reent * r, size_t nmemb, size_t size) {
dkato 0:f782d9c66c49 184 void *ptr = NULL;
dkato 0:f782d9c66c49 185 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 186 // Note - no lock needed since malloc is thread safe
dkato 0:f782d9c66c49 187
dkato 0:f782d9c66c49 188 ptr = malloc(nmemb * size);
dkato 0:f782d9c66c49 189 if (ptr != NULL) {
dkato 0:f782d9c66c49 190 memset(ptr, 0, nmemb * size);
dkato 0:f782d9c66c49 191 }
dkato 0:f782d9c66c49 192 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 193 ptr = __real__calloc_r(r, nmemb, size);
dkato 0:f782d9c66c49 194 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 195 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 196 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 197 mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 198 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 199 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 200 return ptr;
dkato 0:f782d9c66c49 201 }
dkato 0:f782d9c66c49 202
dkato 0:f782d9c66c49 203
dkato 0:f782d9c66c49 204 /******************************************************************************/
dkato 0:f782d9c66c49 205 /* ARMCC memory allocation wrappers */
dkato 0:f782d9c66c49 206 /******************************************************************************/
dkato 0:f782d9c66c49 207
dkato 0:f782d9c66c49 208 #elif defined(TOOLCHAIN_ARM) // #if defined(TOOLCHAIN_GCC)
dkato 0:f782d9c66c49 209
dkato 0:f782d9c66c49 210 /* Enable hooking of memory function only if tracing is also enabled */
dkato 0:f782d9c66c49 211 #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
dkato 0:f782d9c66c49 212
dkato 0:f782d9c66c49 213 extern "C" {
dkato 0:f782d9c66c49 214 void *$Super$$malloc(size_t size);
dkato 0:f782d9c66c49 215 void *$Super$$realloc(void *ptr, size_t size);
dkato 0:f782d9c66c49 216 void *$Super$$calloc(size_t nmemb, size_t size);
dkato 0:f782d9c66c49 217 void $Super$$free(void *ptr);
dkato 0:f782d9c66c49 218 }
dkato 0:f782d9c66c49 219
dkato 0:f782d9c66c49 220 extern "C" void* $Sub$$malloc(size_t size) {
dkato 0:f782d9c66c49 221 void *ptr = NULL;
dkato 0:f782d9c66c49 222 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 223 malloc_stats_mutex->lock();
dkato 0:f782d9c66c49 224 alloc_info_t *alloc_info = (alloc_info_t*)$Super$$malloc(size + sizeof(alloc_info_t));
dkato 0:f782d9c66c49 225 if (alloc_info != NULL) {
dkato 0:f782d9c66c49 226 alloc_info->size = size;
dkato 0:f782d9c66c49 227 ptr = (void*)(alloc_info + 1);
dkato 0:f782d9c66c49 228 heap_stats.current_size += size;
dkato 0:f782d9c66c49 229 heap_stats.total_size += size;
dkato 0:f782d9c66c49 230 heap_stats.alloc_cnt += 1;
dkato 0:f782d9c66c49 231 if (heap_stats.current_size > heap_stats.max_size) {
dkato 0:f782d9c66c49 232 heap_stats.max_size = heap_stats.current_size;
dkato 0:f782d9c66c49 233 }
dkato 0:f782d9c66c49 234 } else {
dkato 0:f782d9c66c49 235 heap_stats.alloc_fail_cnt += 1;
dkato 0:f782d9c66c49 236 }
dkato 0:f782d9c66c49 237 malloc_stats_mutex->unlock();
dkato 0:f782d9c66c49 238 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 239 ptr = $Super$$malloc(size);
dkato 0:f782d9c66c49 240 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 241 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 242 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 243 mbed_mem_trace_malloc(ptr, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 244 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 245 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 246 return ptr;
dkato 0:f782d9c66c49 247 }
dkato 0:f782d9c66c49 248
dkato 0:f782d9c66c49 249 extern "C" void* $Sub$$realloc(void *ptr, size_t size) {
dkato 0:f782d9c66c49 250 void *new_ptr = NULL;
dkato 0:f782d9c66c49 251 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 252 // Note - no lock needed since malloc and free are thread safe
dkato 0:f782d9c66c49 253
dkato 0:f782d9c66c49 254 // Get old size
dkato 0:f782d9c66c49 255 uint32_t old_size = 0;
dkato 0:f782d9c66c49 256 if (ptr != NULL) {
dkato 0:f782d9c66c49 257 alloc_info_t *alloc_info = ((alloc_info_t*)ptr) - 1;
dkato 0:f782d9c66c49 258 old_size = alloc_info->size;
dkato 0:f782d9c66c49 259 }
dkato 0:f782d9c66c49 260
dkato 0:f782d9c66c49 261 // Allocate space
dkato 0:f782d9c66c49 262 if (size != 0) {
dkato 0:f782d9c66c49 263 new_ptr = malloc(size);
dkato 0:f782d9c66c49 264 }
dkato 0:f782d9c66c49 265
dkato 0:f782d9c66c49 266 // If the new buffer has been allocated copy the data to it
dkato 0:f782d9c66c49 267 // and free the old buffer
dkato 0:f782d9c66c49 268 if (new_ptr != NULL) {
dkato 0:f782d9c66c49 269 uint32_t copy_size = (old_size < size) ? old_size : size;
dkato 0:f782d9c66c49 270 memcpy(new_ptr, (void*)ptr, copy_size);
dkato 0:f782d9c66c49 271 free(ptr);
dkato 0:f782d9c66c49 272 }
dkato 0:f782d9c66c49 273 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 274 new_ptr = $Super$$realloc(ptr, size);
dkato 0:f782d9c66c49 275 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 276 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 277 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 278 mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 279 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 280 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 281 return new_ptr;
dkato 0:f782d9c66c49 282 }
dkato 0:f782d9c66c49 283
dkato 0:f782d9c66c49 284 extern "C" void *$Sub$$calloc(size_t nmemb, size_t size) {
dkato 0:f782d9c66c49 285 void *ptr = NULL;
dkato 0:f782d9c66c49 286 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 287 // Note - no lock needed since malloc is thread safe
dkato 0:f782d9c66c49 288 ptr = malloc(nmemb * size);
dkato 0:f782d9c66c49 289 if (ptr != NULL) {
dkato 0:f782d9c66c49 290 memset(ptr, 0, nmemb * size);
dkato 0:f782d9c66c49 291 }
dkato 0:f782d9c66c49 292 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 293 ptr = $Super$$calloc(nmemb, size);
dkato 0:f782d9c66c49 294 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 295 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 296 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 297 mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 298 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 299 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 300 return ptr;
dkato 0:f782d9c66c49 301 }
dkato 0:f782d9c66c49 302
dkato 0:f782d9c66c49 303 extern "C" void $Sub$$free(void *ptr) {
dkato 0:f782d9c66c49 304 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 305 malloc_stats_mutex->lock();
dkato 0:f782d9c66c49 306 alloc_info_t *alloc_info = NULL;
dkato 0:f782d9c66c49 307 if (ptr != NULL) {
dkato 0:f782d9c66c49 308 alloc_info = ((alloc_info_t*)ptr) - 1;
dkato 0:f782d9c66c49 309 heap_stats.current_size -= alloc_info->size;
dkato 0:f782d9c66c49 310 heap_stats.alloc_cnt -= 1;
dkato 0:f782d9c66c49 311 }
dkato 0:f782d9c66c49 312 $Super$$free((void*)alloc_info);
dkato 0:f782d9c66c49 313 malloc_stats_mutex->unlock();
dkato 0:f782d9c66c49 314 #else // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 315 $Super$$free(ptr);
dkato 0:f782d9c66c49 316 #endif // #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 317 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 318 mem_trace_mutex->lock();
dkato 0:f782d9c66c49 319 mbed_mem_trace_free(ptr, MBED_CALLER_ADDR());
dkato 0:f782d9c66c49 320 mem_trace_mutex->unlock();
dkato 0:f782d9c66c49 321 #endif // #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 322 }
dkato 0:f782d9c66c49 323
dkato 0:f782d9c66c49 324 #endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
dkato 0:f782d9c66c49 325
dkato 0:f782d9c66c49 326 /******************************************************************************/
dkato 0:f782d9c66c49 327 /* Allocation wrappers for other toolchains are not supported yet */
dkato 0:f782d9c66c49 328 /******************************************************************************/
dkato 0:f782d9c66c49 329
dkato 0:f782d9c66c49 330 #else // #if defined(TOOLCHAIN_GCC)
dkato 0:f782d9c66c49 331
dkato 0:f782d9c66c49 332 #ifdef MBED_MEM_TRACING_ENABLED
dkato 0:f782d9c66c49 333 #warning Memory tracing is not supported with the current toolchain.
dkato 0:f782d9c66c49 334 #endif
dkato 0:f782d9c66c49 335
dkato 0:f782d9c66c49 336 #ifdef MBED_HEAP_STATS_ENABLED
dkato 0:f782d9c66c49 337 #warning Heap statistics are not supported with the current toolchain.
dkato 0:f782d9c66c49 338 #endif
dkato 0:f782d9c66c49 339
dkato 0:f782d9c66c49 340 #endif // #if defined(TOOLCHAIN_GCC)
dkato 0:f782d9c66c49 341