tpl_utils: Added internal util function to find node from given list with data. 02/185002/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 25 Jul 2018 06:35:03 +0000 (15:35 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Wed, 25 Jul 2018 06:35:03 +0000 (15:35 +0900)
Change-Id: I5754db81f7edc27728d7b839985a124923671e6f
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils.h

index 11aad8c..4237247 100644 (file)
@@ -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)