mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00

Add a simple singly linked list implementation when double linked list are not needed. This allows to easily have statically defined linked list that can be extended at runtime. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
34 lines
724 B
C
34 lines
724 B
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Simple simply-linked list library.
|
|
*
|
|
* Copyright (c) 2025 Rivos Inc.
|
|
*
|
|
* Authors:
|
|
* Clément Léger <cleger@rivosinc.com>
|
|
*/
|
|
|
|
#ifndef __SBI_SLIST_H__
|
|
#define __SBI_SLIST_H__
|
|
|
|
#include <sbi/sbi_types.h>
|
|
|
|
#define SBI_SLIST_HEAD_INIT(_ptr) (_ptr)
|
|
#define SBI_SLIST_HEAD(_lname, _stype) struct _stype *_lname
|
|
#define SBI_SLIST_NODE(_stype) SBI_SLIST_HEAD(next, _stype)
|
|
#define SBI_SLIST_NODE_INIT(_ptr) .next = _ptr
|
|
|
|
#define SBI_INIT_SLIST_HEAD(_head) (_head) = NULL
|
|
|
|
#define SBI_SLIST_ADD(_ptr, _head) \
|
|
do { \
|
|
(_ptr)->next = _head; \
|
|
(_head) = _ptr; \
|
|
} while (0)
|
|
|
|
#define SBI_SLIST_FOR_EACH_ENTRY(_ptr, _head) \
|
|
for (_ptr = _head; _ptr; _ptr = _ptr->next)
|
|
|
|
#endif
|