From 4d5a8b2f99be5e04954c5067080d1725af8c0ae7 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 7 Apr 2025 00:09:00 -0600 Subject: libcr_ipc: Pull as much as possible from public .h to .c files --- libcr_ipc/_linkedlist.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 libcr_ipc/_linkedlist.c (limited to 'libcr_ipc/_linkedlist.c') diff --git a/libcr_ipc/_linkedlist.c b/libcr_ipc/_linkedlist.c new file mode 100644 index 0000000..b27dba8 --- /dev/null +++ b/libcr_ipc/_linkedlist.c @@ -0,0 +1,62 @@ +/* libcr_ipc/_linkedlist.c - Common low-level linked lists for use in libcr_ipc + * + * Copyright (C) 2024-2025 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include /* for NULL */ + +#include "_linkedlist.h" + +/* singly linked list *********************************************************/ + +void cr_ipc_sll_push_to_rear(_cr_ipc_sll_root *root, cr_ipc_sll_node *node) { + assert(root); + node->rear = NULL; + if (root->rear) + root->rear->rear = node; + else + root->front = node; + root->rear = node; +} + +void cr_ipc_sll_pop_from_front(_cr_ipc_sll_root *root) { + assert(root); + assert(root->front); + root->front = root->front->rear; + if (!root->front) + root->rear = NULL; +} + +/* doubly linked list *********************************************************/ + +void cr_ipc_dll_push_to_rear(_cr_ipc_dll_root *root, cr_ipc_dll_node *node) { + assert(root); + assert(node); + node->front = root->rear; + node->rear = NULL; + if (root->rear) + root->rear->rear = node; + else + root->front = node; + root->rear = node; +} + +void cr_ipc_dll_remove(_cr_ipc_dll_root *root, cr_ipc_dll_node *node) { + assert(root); + assert(node); + if (node->front) + node->front->rear = node->rear; + else + root->front = node->rear; + if (node->rear) + node->rear->front = node->front; + else + root->rear = node->front; +} + +void cr_ipc_dll_pop_from_front(_cr_ipc_dll_root *root) { + assert(root); + assert(root->front); + cr_ipc_dll_remove(root, root->front); +} -- cgit v1.2.3-2-g168b