mbed library sources, mbed-dev only for TYBLE16

Fork of mbed-dev by mbed official

Please refer flowing link.
/users/kenjiArai/notebook/tyble16-module-will-become-a-mbed-family--mbedliza/

Revision:
180:96ed750bd169
Parent:
174:b96e65c34a4d
Child:
181:57724642e740
--- a/platform/mbed_alloc_wrappers.cpp	Thu Dec 07 14:01:42 2017 +0000
+++ b/platform/mbed_alloc_wrappers.cpp	Wed Jan 17 15:23:54 2018 +0000
@@ -46,9 +46,6 @@
     uint32_t pad;
 } alloc_info_t;
 
-#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};
@@ -91,6 +88,9 @@
 
 extern "C" void * __wrap__malloc_r(struct _reent * r, size_t size) {
     void *ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     malloc_stats_mutex->lock();
     alloc_info_t *alloc_info = (alloc_info_t*)__real__malloc_r(r, size + sizeof(alloc_info_t));
@@ -111,15 +111,17 @@
     ptr = __real__malloc_r(r, size);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_malloc(ptr, size, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return ptr;
 }
 
 extern "C" void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size) {
     void *new_ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     // Implement realloc_r with malloc and free.
     // The function realloc_r can't be used here directly since
@@ -151,14 +153,16 @@
     new_ptr = __real__realloc_r(r, ptr, size);
 #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();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return new_ptr;
 }
 
 extern "C" void __wrap__free_r(struct _reent * r, void * ptr) {
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     malloc_stats_mutex->lock();
     alloc_info_t *alloc_info = NULL;
@@ -173,14 +177,16 @@
     __real__free_r(r, ptr);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_free(ptr, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
 }
 
 extern "C" void * __wrap__calloc_r(struct _reent * r, size_t nmemb, size_t size) {
     void *ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     // Note - no lock needed since malloc is thread safe
 
@@ -192,9 +198,8 @@
     ptr = __real__calloc_r(r, nmemb, size);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return ptr;
 }
@@ -244,6 +249,9 @@
 
 extern "C" void* SUB_MALLOC(size_t size) {
     void *ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     malloc_stats_mutex->lock();
     alloc_info_t *alloc_info = (alloc_info_t*)SUPER_MALLOC(size + sizeof(alloc_info_t));
@@ -264,15 +272,17 @@
     ptr = SUPER_MALLOC(size);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_malloc(ptr, size, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return ptr;
 }
 
 extern "C" void* SUB_REALLOC(void *ptr, size_t size) {
     void *new_ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     // Note - no lock needed since malloc and free are thread safe
 
@@ -299,15 +309,17 @@
     new_ptr = SUPER_REALLOC(ptr, size);
 #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();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return new_ptr;
 }
 
 extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) {
     void *ptr = NULL;
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     // Note - no lock needed since malloc is thread safe
     ptr = malloc(nmemb * size);
@@ -318,14 +330,16 @@
     ptr = SUPER_CALLOC(nmemb, size);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
     return ptr;
 }
 
 extern "C" void SUB_FREE(void *ptr) {
+#ifdef MBED_MEM_TRACING_ENABLED
+    mbed_mem_trace_lock();
+#endif
 #ifdef MBED_HEAP_STATS_ENABLED
     malloc_stats_mutex->lock();
     alloc_info_t *alloc_info = NULL;
@@ -340,9 +354,8 @@
     SUPER_FREE(ptr);
 #endif // #ifdef MBED_HEAP_STATS_ENABLED
 #ifdef MBED_MEM_TRACING_ENABLED
-    mem_trace_mutex->lock();
     mbed_mem_trace_free(ptr, MBED_CALLER_ADDR());
-    mem_trace_mutex->unlock();
+    mbed_mem_trace_unlock();
 #endif // #ifdef MBED_MEM_TRACING_ENABLED
 }