Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
heap_listener.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_HEAP_LISTENER_H
8#define ZEPHYR_INCLUDE_SYS_HEAP_LISTENER_H
9
10#include <stdint.h>
11#include <zephyr/toolchain.h>
12#include <zephyr/sys/slist.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#if defined(CONFIG_HEAP_LISTENER) || defined(__DOXYGEN__)
19
27 /*
28 * Dummy event so an un-initialized but zero-ed listener node
29 * will not trigger any callbacks.
30 */
32
37
39};
40
51typedef void (*heap_listener_resize_cb_t)(uintptr_t heap_id,
52 void *old_heap_end,
53 void *new_heap_end);
54
71typedef void (*heap_listener_alloc_cb_t)(uintptr_t heap_id,
72 void *mem, size_t bytes);
73
90typedef void (*heap_listener_free_cb_t)(uintptr_t heap_id,
91 void *mem, size_t bytes);
92
116
126
137
148void heap_listener_notify_alloc(uintptr_t heap_id, void *mem, size_t bytes);
149
160void heap_listener_notify_free(uintptr_t heap_id, void *mem, size_t bytes);
161
172void heap_listener_notify_resize(uintptr_t heap_id, void *old_heap_end, void *new_heap_end);
173
182#define HEAP_ID_FROM_POINTER(heap_pointer) ((uintptr_t)heap_pointer)
183
189#define HEAP_ID_LIBC ((uintptr_t)0)
190
208#define HEAP_LISTENER_ALLOC_DEFINE(name, _heap_id, _alloc_cb) \
209 struct heap_listener name = { \
210 .heap_id = _heap_id, \
211 .event = HEAP_ALLOC, \
212 { \
213 .alloc_cb = _alloc_cb \
214 }, \
215 }
216
234#define HEAP_LISTENER_FREE_DEFINE(name, _heap_id, _free_cb) \
235 struct heap_listener name = { \
236 .heap_id = _heap_id, \
237 .event = HEAP_FREE, \
238 { \
239 .free_cb = _free_cb \
240 }, \
241 }
242
260#define HEAP_LISTENER_RESIZE_DEFINE(name, _heap_id, _resize_cb) \
261 struct heap_listener name = { \
262 .heap_id = _heap_id, \
263 .event = HEAP_RESIZE, \
264 { \
265 .resize_cb = _resize_cb \
266 }, \
267 }
268
271#else /* CONFIG_HEAP_LISTENER */
272
273#define HEAP_ID_FROM_POINTER(heap_pointer) ((uintptr_t)NULL)
274
275static inline void heap_listener_notify_alloc(uintptr_t heap_id, void *mem, size_t bytes)
276{
277 ARG_UNUSED(heap_id);
278 ARG_UNUSED(mem);
279 ARG_UNUSED(bytes);
280}
281
282static inline void heap_listener_notify_free(uintptr_t heap_id, void *mem, size_t bytes)
283{
284 ARG_UNUSED(heap_id);
285 ARG_UNUSED(mem);
286 ARG_UNUSED(bytes);
287}
288
289static inline void heap_listener_notify_resize(uintptr_t heap_id, void *old_heap_end,
290 void *new_heap_end)
291{
292 ARG_UNUSED(heap_id);
293 ARG_UNUSED(old_heap_end);
294 ARG_UNUSED(new_heap_end);
295}
296
297#endif /* CONFIG_HEAP_LISTENER */
298
299#ifdef __cplusplus
300}
301#endif
302
303#endif /* ZEPHYR_INCLUDE_SYS_HEAP_LISTENER_H */
void(* heap_listener_alloc_cb_t)(uintptr_t heap_id, void *mem, size_t bytes)
Callback used when there is heap allocation.
Definition heap_listener.h:71
void heap_listener_register(struct heap_listener *listener)
Register heap event listener.
void heap_listener_unregister(struct heap_listener *listener)
Unregister heap event listener.
void(* heap_listener_free_cb_t)(uintptr_t heap_id, void *mem, size_t bytes)
Callback used when memory is freed from heap.
Definition heap_listener.h:90
void heap_listener_notify_free(uintptr_t heap_id, void *mem, size_t bytes)
Notify listeners of heap free event.
heap_event_types
Definition heap_listener.h:26
void heap_listener_notify_resize(uintptr_t heap_id, void *old_heap_end, void *new_heap_end)
Notify listeners of heap resize event.
void(* heap_listener_resize_cb_t)(uintptr_t heap_id, void *old_heap_end, void *new_heap_end)
Callback used when heap is resized.
Definition heap_listener.h:51
void heap_listener_notify_alloc(uintptr_t heap_id, void *mem, size_t bytes)
Notify listeners of heap allocation event.
@ HEAP_RESIZE
Definition heap_listener.h:33
@ HEAP_ALLOC
Definition heap_listener.h:34
@ HEAP_FREE
Definition heap_listener.h:35
@ HEAP_REALLOC
Definition heap_listener.h:36
@ HEAP_EVT_UNKNOWN
Definition heap_listener.h:31
@ HEAP_MAX_EVENTS
Definition heap_listener.h:38
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Definition heap_listener.h:93
heap_listener_resize_cb_t resize_cb
Definition heap_listener.h:113
enum heap_event_types event
The heap event to be notified.
Definition heap_listener.h:108
heap_listener_alloc_cb_t alloc_cb
Definition heap_listener.h:111
heap_listener_free_cb_t free_cb
Definition heap_listener.h:112
uintptr_t heap_id
Identifier of the heap whose events are listened.
Definition heap_listener.h:103
sys_snode_t node
Singly linked list node.
Definition heap_listener.h:95
Macros to abstract toolchain specific capabilities.