From 7e15e12d459b71d97911ba3c886ac805e0defe0f Mon Sep 17 00:00:00 2001 From: max Date: Mon, 28 Oct 2024 20:08:30 +0100 Subject: [PATCH] [CHANGE] 'iterate_list' function handles by flags --- src/net/collections/list.c | 14 +++++++++++--- src/net/include/list.h | 8 ++++++++ src/net/logging/log.c | 4 +--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/net/collections/list.c b/src/net/collections/list.c index e7c93e7..f7e85ab 100644 --- a/src/net/collections/list.c +++ b/src/net/collections/list.c @@ -55,12 +55,20 @@ void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*)) list_node * current = list; while (current != NULL) { - if (iterFunc(current->data) == 1) + list_node* temp_next = current->next; + list_node* temp_previous = current->previous; + + // State + int iter_state = iterFunc(current->data); + if (iter_state & DELETE) + delete_node(current); + if (iter_state & BREAK) break; + if (forward) - current = current->next; + current = temp_next; else - current = current->previous; + current = temp_previous; } } diff --git a/src/net/include/list.h b/src/net/include/list.h index b83ca71..fccdfd3 100644 --- a/src/net/include/list.h +++ b/src/net/include/list.h @@ -2,6 +2,13 @@ #define NETEX_LIST_H +typedef enum list_iterate_states +{ + CONTINUE = 0 << 0, + BREAK = 1 << 0, + DELETE = 1 << 1 +}iterate_state; + typedef struct list_node { void* data; @@ -9,6 +16,7 @@ typedef struct list_node struct list_node* next; } list_node; +void delete_node(list_node* node); void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*)); #endif //NETEX_LIST_H diff --git a/src/net/logging/log.c b/src/net/logging/log.c index b8ce7cd..b3f684f 100755 --- a/src/net/logging/log.c +++ b/src/net/logging/log.c @@ -18,7 +18,7 @@ int shutdown_logger(const void* data) logger->app_logger = NULL; logger->name = NULL; free(logger); - return 0; + return DELETE | BREAK; } void shutdown_log(app_logger_info* appLogger) @@ -27,8 +27,6 @@ void shutdown_log(app_logger_info* appLogger) iterate_list(appLogger->loggers, true, &shutdown_logger); } - - logger* create_logger(app_logger_info* appLogger, char* name) { return NULL;