I like to moving

This commit is contained in:
SG
2024-04-08 04:05:44 +03:00
parent 2a234e4129
commit 5e3d3d5dbe

View File

@@ -3,6 +3,7 @@
#include <tlsf_block_functions.h>
#include <FreeRTOS.h>
#include <task.h>
#include <m-dict.h>
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 <m-dict.h>
// 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()) {