From 5e3d3d5dbe1878b9fe6cb7d99d73e9f6a835c991 Mon Sep 17 00:00:00 2001 From: SG Date: Mon, 8 Apr 2024 04:05:44 +0300 Subject: [PATCH] I like to moving --- furi/core/memmgr_heap.c | 60 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/furi/core/memmgr_heap.c b/furi/core/memmgr_heap.c index f45c2da3b..fd0d1df5e 100644 --- a/furi/core/memmgr_heap.c +++ b/furi/core/memmgr_heap.c @@ -3,6 +3,7 @@ #include #include #include +#include extern const void __heap_start__; extern const void __heap_end__; @@ -11,9 +12,6 @@ static tlsf_t tlsf = NULL; static size_t heap_used = 0; static size_t heap_max_used = 0; -// Furi heap extension -#include - // Allocation tracking types DICT_DEF2(MemmgrHeapAllocDict, uint32_t, uint32_t) //-V1048 @@ -69,6 +67,34 @@ void memmgr_heap_disable_thread_trace(FuriThreadId thread_id) { memmgr_unlock(); } +static inline void memmgr_heap_trace_malloc(void* pointer, size_t size) { + FuriThreadId thread_id = furi_thread_get_current_id(); + if(thread_id && memmgr_heap_thread_trace_depth == 0) { + memmgr_heap_thread_trace_depth++; + MemmgrHeapAllocDict_t* alloc_dict = + MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id); + if(alloc_dict) { + MemmgrHeapAllocDict_set_at(*alloc_dict, (uint32_t)pointer, (uint32_t)size); + } + memmgr_heap_thread_trace_depth--; + } +} + +static inline void memmgr_heap_trace_free(void* pointer) { + FuriThreadId thread_id = furi_thread_get_current_id(); + if(thread_id && memmgr_heap_thread_trace_depth == 0) { + memmgr_heap_thread_trace_depth++; + MemmgrHeapAllocDict_t* alloc_dict = + MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id); + if(alloc_dict) { + // In some cases thread may want to release memory that was not allocated by it + const bool res = MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer); + UNUSED(res); + } + memmgr_heap_thread_trace_depth--; + } +} + size_t memmgr_heap_get_thread_memory(FuriThreadId thread_id) { size_t leftovers = MEMMGR_HEAP_UNKNOWN; vTaskSuspendAll(); @@ -143,34 +169,6 @@ void memmgr_heap_walk_blocks(BlockWalker walker, void* context) { memmgr_unlock(); } -static inline void memmgr_heap_trace_malloc(void* pointer, size_t size) { - FuriThreadId thread_id = furi_thread_get_current_id(); - if(thread_id && memmgr_heap_thread_trace_depth == 0) { - memmgr_heap_thread_trace_depth++; - MemmgrHeapAllocDict_t* alloc_dict = - MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id); - if(alloc_dict) { - MemmgrHeapAllocDict_set_at(*alloc_dict, (uint32_t)pointer, (uint32_t)size); - } - memmgr_heap_thread_trace_depth--; - } -} - -static inline void memmgr_heap_trace_free(void* pointer) { - FuriThreadId thread_id = furi_thread_get_current_id(); - if(thread_id && memmgr_heap_thread_trace_depth == 0) { - memmgr_heap_thread_trace_depth++; - MemmgrHeapAllocDict_t* alloc_dict = - MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id); - if(alloc_dict) { - // In some cases thread may want to release memory that was not allocated by it - const bool res = MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer); - UNUSED(res); - } - memmgr_heap_thread_trace_depth--; - } -} - void* pvPortMalloc(size_t xSize) { // memory management in ISR is not allowed if(FURI_IS_IRQ_MODE()) {