Browse Source

include: zephyr: sys: Refactor MIN_HEAP_DEFINE macro

Remove calling of `min_heap_init()` from MIN_HEAP_DEFINE

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
pull/89265/head
Sayooj K Karun 3 weeks ago committed by Anas Nashif
parent
commit
41adc8a61a
  1. 20
      include/zephyr/sys/min_heap.h
  2. 5
      tests/lib/min_heap/src/test_min_heap.c

20
include/zephyr/sys/min_heap.h

@ -66,17 +66,21 @@ struct min_heap { @@ -66,17 +66,21 @@ struct min_heap {
};
/**
* @brief Define and initialize a heap instance at runtime.
* @brief Define a min-heap instance.
*
* @param name Name of the heap variable.
* @param storage Pointer to the preallocated storage.
* @param name Base name for the heap instance.
* @param cap Capacity (number of elements).
* @param size Size of each element.
* @param cmp_func Comparator function for the heap.
* @param elem_sz Size in bytes of each element.
* @param align Required alignment of each element.
* @param cmp_func Comparator function used by the heap
*/
#define MIN_HEAP_DEFINE(name, storage, cap, size, cmp_func) \
struct min_heap name; \
min_heap_init(&name, storage, cap, size, cmp_func)
#define MIN_HEAP_DEFINE(name, cap, elem_sz, align, cmp_func) \
static uint8_t name##_storage[(cap) * (elem_sz)] __aligned(align); \
struct min_heap name = {.storage = name##_storage, \
.capacity = (cap), \
.elem_size = (elem_sz), \
.size = 0, \
.cmp = (cmp_func)}
/**
* @brief Define a statically allocated and aligned min-heap instance.

5
tests/lib/min_heap/src/test_min_heap.c

@ -136,10 +136,9 @@ ZTEST(min_heap_api, test_insert) @@ -136,10 +136,9 @@ ZTEST(min_heap_api, test_insert)
ZTEST(min_heap_api, test_peek_and_pop)
{
int ret;
uint8_t storage[HEAP_CAPACITY * sizeof(struct data)];
MIN_HEAP_DEFINE(runtime_heap, storage, HEAP_CAPACITY,
sizeof(struct data), compare_ls);
MIN_HEAP_DEFINE_STATIC(runtime_heap, HEAP_CAPACITY, sizeof(struct data),
__alignof__(struct data), compare_ls);
for (int i = 0; i < ARRAY_SIZE(elements); i++) {

Loading…
Cancel
Save