From 278e880e62892c712e52d32dacd6e83882208f6c Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 5 Apr 2023 11:12:01 +0200 Subject: [PATCH] created waiting llist it contains only function for push --- src/chat/misc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/chat/misc.c b/src/chat/misc.c index b7c2fa7..a0c719b 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -44,7 +44,14 @@ typedef struct node struct node *next; } node_t; //SINGLE LINKED LIST +typedef struct waiting_node +{ + pthread_t thread; + struct waiting_node *next; +} waiting_node_t; //SINGLE LINKED LIST + node_t *head = NULL; +waiting_node_t *waiting_head = NULL; void push_to_list(int connection, pthread_t thread) { @@ -67,6 +74,26 @@ void push_to_list(int connection, pthread_t thread) } } +void waiting_push_to_list(pthread_t thread) +{ + //CREATE NODE + waiting_node_t *new_node = malloc(sizeof(waiting_node_t)); + waiting_node_t *buffer = waiting_head; + + new_node -> thread = thread; + new_node -> next = NULL; + + if (waiting_head == NULL) //INIT LIST + { + waiting_head = new_node; + } else + { + while (buffer -> next != NULL) buffer = buffer -> next; //GET TO THE END OF LIST + + buffer -> next = new_node; //LINK + } +} + void remove_node(node_t *node) { if (node == NULL) return; //NULL NODE