From a39d57611f9f64dcda6efe72fa6ed4ba54107f2e Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 25 Jul 2018 15:35:03 +0900 Subject: [PATCH] tpl_utils: Added internal util function to find node from given list with data. Change-Id: I5754db81f7edc27728d7b839985a124923671e6f Signed-off-by: Joonbum Ko --- src/tpl_utils.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 11aad8c..4237247 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -569,6 +569,52 @@ __tpl_list_insert(tpl_list_node_t *pos, void *data) return TPL_ERROR_NONE; } +static TPL_INLINE tpl_list_node_t * +__tpl_list_find_node(tpl_list_t *list, void *data, int occurrence, + tpl_free_func_t func) +{ + tpl_list_node_t *node = NULL; + tpl_list_node_t *res_node = NULL; + + TPL_ASSERT(list); + + if (occurrence == TPL_FIRST) { + node = list->head.next; + + while (node != &list->tail) { + tpl_list_node_t *curr; + + curr = node; + node = node->next; + + TPL_ASSERT(curr); + TPL_ASSERT(node); + + if (curr->data == data) { + res_node = curr; + } + } + } else if (occurrence == TPL_LAST) { + node = list->tail.prev; + + while (node != &list->head) { + tpl_list_node_t *curr; + + curr = node; + node = node->prev; + + TPL_ASSERT(curr); + TPL_ASSERT(node); + + if (curr->data == data) { + res_node = curr; + } + } + } + + return res_node; +} + static TPL_INLINE void __tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence, tpl_free_func_t func) -- 2.7.4