123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #ifndef ZEPHYR_INCLUDE_SYS_SYS_HEAP_H_
- #define ZEPHYR_INCLUDE_SYS_SYS_HEAP_H_
- #include <stddef.h>
- #include <stdbool.h>
- #include <zephyr/types.h>
- struct sys_heap {
- struct z_heap *heap;
- void *init_mem;
- size_t init_bytes;
- };
- struct z_heap_stress_result {
- uint32_t total_allocs;
- uint32_t successful_allocs;
- uint32_t total_frees;
- uint64_t accumulated_in_use_bytes;
- };
- void sys_heap_init(struct sys_heap *heap, void *mem, size_t bytes);
- void *sys_heap_alloc(struct sys_heap *heap, size_t bytes);
- void *sys_heap_aligned_alloc(struct sys_heap *heap, size_t align, size_t bytes);
- void sys_heap_free(struct sys_heap *heap, void *mem);
- void *sys_heap_aligned_realloc(struct sys_heap *heap, void *ptr,
- size_t align, size_t bytes);
- #define sys_heap_realloc(heap, ptr, bytes) \
- sys_heap_aligned_realloc(heap, ptr, 0, bytes)
- bool sys_heap_validate(struct sys_heap *heap);
- void sys_heap_stress(void *(*alloc_fn)(void *arg, size_t bytes),
- void (*free_fn)(void *arg, void *p),
- void *arg, size_t total_bytes,
- uint32_t op_count,
- void *scratch_mem, size_t scratch_bytes,
- int target_percent,
- struct z_heap_stress_result *result);
- void sys_heap_print_info(struct sys_heap *heap, bool dump_chunks);
- void sys_heap_dump(struct sys_heap *heap);
- #endif
|