Skip to content

Commit 8a13cbb

Browse files
committed
Add container_of helpers for embedded node design
Introduce a simple container operation to support embedded node design for the timer and scheduler subsystems This change allows container access from the embedded list node.
1 parent afa6148 commit 8a13cbb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/private/utils.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88
*/
99

1010
#include <lib/libc.h>
11+
#include <stddef.h>
12+
13+
/*
14+
* container_of - get the pointer to the parent structure from a member pointer
15+
*
16+
* @ptr: pointer to the struct member
17+
* @type: type of the parent structure
18+
* @member: name of the member within the parent structure
19+
*
20+
* This macro computes the address of the parent structure by subtracting
21+
* the member's offset within the structure.
22+
*/
23+
#define container_of(ptr, type, member) \
24+
((type *) ((char *) (ptr) - offsetof(type, member)))
25+
26+
/* Return the tcb_t */
27+
#define tcb_from_global_node(p) container_of(p, tcb_t, global_node)
28+
29+
/* Member access for timer_t */
30+
#define timer_from_node(p) container_of(p, timer_t, t_node)
31+
#define timer_from_running_node(p) container_of(p, timer_t, t_running_node)
1132

1233
/* Compiler Optimization Hints
1334
*

0 commit comments

Comments
 (0)