-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/add-heap-walker-api' into 'master'
feat(heap): Add walker to the heap component Closes IDF-9189 See merge request espressif/esp-idf!29047
- Loading branch information
Showing
20 changed files
with
436 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** @brief Opaque handle to a registered heap */ | ||
typedef struct multi_heap_info *multi_heap_handle_t; | ||
|
||
/** | ||
* @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: free, 1: allocated | ||
* @param user_data Opaque pointer to user defined data | ||
* | ||
* @return True if the walker is expected to continue the heap traversal | ||
* False if the walker is expected to stop the traversal of the heap | ||
*/ | ||
typedef bool (*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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
#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; | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.