Browse Source

kernel: add `k_heap_array_get`

Add `k_heap_array_get` as an alternative to `sys_heap_array_get`, which
only returns statically defined heaps (those defined with
`K_HEAP_DEFINE` or `K_HEAP_DEFINE_NOCACHE`), but doesn't depend on the
application guessing a value for `CONFIG_SYS_HEAP_ARRAY_SIZE`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
pull/91733/merge
Jordan Yates 3 weeks ago committed by Benjamin Cabé
parent
commit
117b452b50
  1. 1
      doc/releases/release-notes-4.2.rst
  2. 11
      include/zephyr/kernel.h
  3. 11
      kernel/kheap.c

1
doc/releases/release-notes-4.2.rst

@ -132,6 +132,7 @@ New APIs and options
* :c:func:`timespec_normalize` * :c:func:`timespec_normalize`
* :c:func:`timespec_from_timeout` * :c:func:`timespec_from_timeout`
* :c:func:`timespec_to_timeout` * :c:func:`timespec_to_timeout`
* :c:func:`k_heap_array_get`
* I2C * I2C

11
include/zephyr/kernel.h

@ -5854,6 +5854,17 @@ void k_heap_free(struct k_heap *h, void *mem) __attribute_nonnull(1);
#define K_HEAP_DEFINE_NOCACHE(name, bytes) \ #define K_HEAP_DEFINE_NOCACHE(name, bytes) \
Z_HEAP_DEFINE_IN_SECT(name, bytes, __nocache) Z_HEAP_DEFINE_IN_SECT(name, bytes, __nocache)
/** @brief Get the array of statically defined heaps
*
* Returns the pointer to the start of the static heap array.
* Static heaps are those declared through one of the `K_HEAP_DEFINE`
* macros.
*
* @param heap Pointer to location where heap array address is written
* @return Number of static heaps
*/
int k_heap_array_get(struct k_heap **heap);
/** /**
* @} * @}
*/ */

11
kernel/kheap.c

@ -12,6 +12,17 @@
#include <ksched.h> #include <ksched.h>
#include <wait_q.h> #include <wait_q.h>
int k_heap_array_get(struct k_heap **heap)
{
int num;
/* Pointer to the start of the heap array */
STRUCT_SECTION_GET(k_heap, 0, heap);
/* Number of statically defined heaps */
STRUCT_SECTION_COUNT(k_heap, &num);
return num;
}
void k_heap_init(struct k_heap *heap, void *mem, size_t bytes) void k_heap_init(struct k_heap *heap, void *mem, size_t bytes)
{ {
z_waitq_init(&heap->wait_q); z_waitq_init(&heap->wait_q);

Loading…
Cancel
Save