mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-24 17:27:21 +00:00
feat(heap): Add walker to the heap component
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/
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -444,6 +444,48 @@ void heap_caps_dump_all(void);
|
||||
*/
|
||||
size_t heap_caps_get_allocated_size( void *ptr );
|
||||
|
||||
/**
|
||||
* @brief Structure used to store heap related data passed to
|
||||
* the walker callback function
|
||||
*/
|
||||
typedef struct walker_heap_info {
|
||||
intptr_t start; ///< Start address of the heap in which the block is located
|
||||
intptr_t end; ///< End address of the heap in which the block is located
|
||||
} walker_heap_into_t;
|
||||
|
||||
/**
|
||||
* @brief Structure used to store block related data passed to
|
||||
* the walker callback function
|
||||
*/
|
||||
typedef struct walker_block_info {
|
||||
void *ptr; ///< Pointer to the block data
|
||||
size_t size; ///< The size of the block
|
||||
bool used; ///< Block status. True if free, false if used
|
||||
} walker_block_info_t;
|
||||
|
||||
/**
|
||||
* @brief Function callback used to walk the heaps
|
||||
* @see Definition in multi_heap.h
|
||||
*/
|
||||
typedef void (*heap_caps_walker_cb_t)(walker_heap_into_t heap_info, walker_block_info_t block_info, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Function called to walk through the heaps with the given set of capabilities
|
||||
*
|
||||
* @param caps The set of capabilities assigned to the heaps to walk through
|
||||
* @param walker_func Callback called for each block of the heaps being traversed
|
||||
* @param user_data Opaque pointer to user defined data
|
||||
*/
|
||||
void heap_caps_walk(uint32_t caps, heap_caps_walker_cb_t walker_func, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Function called to walk through all heaps defined by the heap component
|
||||
*
|
||||
* @param walker_func Callback called for each block of the heaps being traversed
|
||||
* @param user_data Opaque pointer to user defined data
|
||||
*/
|
||||
void heap_caps_walk_all(heap_caps_walker_cb_t walker_func, void *user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -207,6 +207,26 @@ size_t multi_heap_reset_minimum_free_bytes(multi_heap_handle_t heap);
|
||||
*/
|
||||
void multi_heap_restore_minimum_free_bytes(multi_heap_handle_t heap, const size_t new_minimum_free_bytes_value);
|
||||
|
||||
/**
|
||||
* @brief Callback called when walking the given heap blocks of memory
|
||||
*
|
||||
* @param block_ptr Pointer to the block data
|
||||
* @param block_size The size of the block
|
||||
* @param block_used Block status. 0 if free, else, false
|
||||
* @param user_data Opaque pointer to user defined data
|
||||
*/
|
||||
typedef void (*multi_heap_walker_cb_t)(void *block_ptr, size_t block_size, int block_used, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Call the tlsf_walk_pool function of the heap given as parameter with
|
||||
* the walker function passed as parameter
|
||||
*
|
||||
* @param heap The heap to traverse
|
||||
* @param walker_func The walker to trigger on each block of the heap
|
||||
* @param user_data Opaque pointer to user defined data
|
||||
*/
|
||||
void multi_heap_walk(multi_heap_handle_t heap, multi_heap_walker_cb_t walker_func, void *user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user