Commit 8336d8b1 authored by Gaetan Perrot's avatar Gaetan Perrot Committed by Anas Nashif
Browse files

kernel: api: sys_slist find zephyrproject-rtos#65973



add a function to find a node in a slist.

signed-off-by: default avatarGaetan Perrot <gaetanperrotpro@gmail.com>
parent 8ea1ca73
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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)                         \
	{                                                                                          \
+15 −0
Original line number Diff line number Diff line
@@ -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
 *