kernel: api: sys_slist find zephyrproject-rtos#65973
add a function to find a node in a slist. signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
This commit is contained in:
parent
8ea1ca7355
commit
8336d8b1e1
|
@ -234,6 +234,31 @@
|
|||
return false; \
|
||||
}
|
||||
|
||||
#define Z_GENLIST_FIND(__lname, __nname) \
|
||||
static inline bool sys_##__lname##_find( \
|
||||
sys_##__lname##_t *list, sys_##__nname##_t *node, sys_##__nname##_t **prev) \
|
||||
{ \
|
||||
sys_##__nname##_t *current = NULL; \
|
||||
sys_##__nname##_t *previous = NULL; \
|
||||
\
|
||||
Z_GENLIST_FOR_EACH_NODE(__lname, list, current) { \
|
||||
if (current == node) { \
|
||||
if (prev != NULL) { \
|
||||
*prev = previous; \
|
||||
} \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
previous = current; \
|
||||
} \
|
||||
\
|
||||
if (prev != NULL) { \
|
||||
*prev = previous; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define Z_GENLIST_LEN(__lname, __nname) \
|
||||
static inline size_t sys_##__lname##_len(sys_##__lname##_t * list) \
|
||||
{ \
|
||||
|
|
|
@ -420,6 +420,21 @@ Z_GENLIST_REMOVE(slist, snode)
|
|||
static inline bool sys_slist_find_and_remove(sys_slist_t *list,
|
||||
sys_snode_t *node);
|
||||
|
||||
/**
|
||||
* @brief Find if a node is already linked in a singly linked list
|
||||
*
|
||||
* This and other sys_slist_*() functions are not thread safe.
|
||||
*
|
||||
* @param list A pointer to the list to check
|
||||
* @param node A pointer to the node to search in the list
|
||||
* @param[out] prev A pointer to the previous node
|
||||
*
|
||||
* @return true if node was found in the list, false otherwise
|
||||
*/
|
||||
static inline bool sys_slist_find(sys_slist_t *list, sys_snode_t *node,
|
||||
sys_snode_t **prev);
|
||||
Z_GENLIST_FIND(slist, snode)
|
||||
|
||||
/**
|
||||
* @brief Compute the size of the given list in O(n) time
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue