mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00

Introduce new APIs in essp_heap_caps.h: - heap_caps_walk() - heap_caps_walk_all() Those functions are triggering a callback for all blocks (allocated or free) of memory present in heaps meeting the set of capabilities passed as parameter (or all heaps for heap_caps_walk_all() function) test_walker.c added to test the new functionality in test_apps/heap_test/
59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/*
|
|
* This file is a patch for the multi_heap.c file stored in ROM
|
|
* - added function multi_heap_walk
|
|
* - added function multi_heap_walker
|
|
* - added structure walker_data_t
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#include "esp_rom_multi_heap.h"
|
|
|
|
// Hook to force the linker to include this file
|
|
void esp_rom_include_multi_heap_patch(void)
|
|
{
|
|
}
|
|
|
|
/*!
|
|
* @brief Opaque types for TLSF implementation
|
|
*/
|
|
typedef void* tlsf_t;
|
|
typedef void* pool_t;
|
|
typedef void* tlsf_walker;
|
|
|
|
typedef struct multi_heap_info {
|
|
void *lock;
|
|
size_t free_bytes;
|
|
size_t minimum_free_bytes;
|
|
size_t pool_size;
|
|
void* heap_data;
|
|
} heap_t;
|
|
|
|
typedef struct walker_data {
|
|
void *opaque_ptr;
|
|
multi_heap_walker_cb_t walker;
|
|
multi_heap_handle_t heap;
|
|
} walker_data_t;
|
|
|
|
extern void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
|
|
extern pool_t tlsf_get_pool(tlsf_t tlsf);
|
|
extern void multi_heap_internal_lock(multi_heap_handle_t heap);
|
|
extern void multi_heap_internal_unlock(multi_heap_handle_t heap);
|
|
|
|
void multi_heap_walk(multi_heap_handle_t heap, multi_heap_walker_cb_t walker_func, void *user_data)
|
|
{
|
|
assert(heap != NULL);
|
|
|
|
multi_heap_internal_lock(heap);
|
|
tlsf_walk_pool(tlsf_get_pool(heap->heap_data), walker_func, user_data);
|
|
multi_heap_internal_unlock(heap);
|
|
}
|