summaryrefslogtreecommitdiff
path: root/libcr_ipc/_linkedlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'libcr_ipc/_linkedlist.h')
-rw-r--r--libcr_ipc/_linkedlist.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/libcr_ipc/_linkedlist.h b/libcr_ipc/_linkedlist.h
new file mode 100644
index 0000000..ab6d89e
--- /dev/null
+++ b/libcr_ipc/_linkedlist.h
@@ -0,0 +1,51 @@
+/* libcr_ipc/_linkedlist.h - Common low-level linked lists for use in libcr_ipc
+ *
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#ifndef _LIBCR_IPC__LINKEDLIST_H_
+#define _LIBCR_IPC__LINKEDLIST_H_
+
+#include <libmisc/assert.h>
+
+#include <libcr_ipc/_linkedlist_pub.h>
+
+/* singly linked list *********************************************************/
+
+typedef struct _cr_ipc_sll_node {
+ struct _cr_ipc_sll_node *rear;
+} cr_ipc_sll_node;
+
+#define cr_ipc_sll_node_cast(node_typ, node_ptr) \
+ ({ \
+ static_assert(_Generic(node_ptr, cr_ipc_sll_node *: 1, default: 0), \
+ "typeof("#node_ptr") != cr_ipc_sll_node *"); \
+ assert(node_ptr); \
+ static_assert(offsetof(node_typ, cr_ipc_sll_node) == 0); \
+ ((node_typ*)(node_ptr)); \
+ })
+
+void cr_ipc_sll_push_to_rear(_cr_ipc_sll_root *root, cr_ipc_sll_node *node);
+void cr_ipc_sll_pop_from_front(_cr_ipc_sll_root *root);
+
+/* doubly linked list *********************************************************/
+
+typedef struct _cr_ipc_dll_node {
+ struct _cr_ipc_dll_node *front, *rear;
+} cr_ipc_dll_node;
+
+#define cr_ipc_dll_node_cast(node_typ, node_ptr) \
+ ({ \
+ static_assert(_Generic(node_ptr, cr_ipc_dll_node *: 1, default: 0), \
+ "typeof("#node_ptr") != cr_ipc_dll_node *"); \
+ assert(node_ptr); \
+ static_assert(offsetof(node_typ, cr_ipc_dll_node) == 0); \
+ ((node_typ*)(node_ptr)); \
+ })
+
+void cr_ipc_dll_push_to_rear(_cr_ipc_dll_root *root, cr_ipc_dll_node *node);
+void cr_ipc_dll_remove(_cr_ipc_dll_root *root, cr_ipc_dll_node *node);
+void cr_ipc_dll_pop_from_front(_cr_ipc_dll_root *root);
+
+#endif /* _LIBCR_IPC__LINKEDLIST_H_ */