diff options
| author | Clément Léger <[email protected]> | 2025-01-10 14:15:53 +0100 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2025-01-30 10:35:46 +0530 |
| commit | 147978f3124418609c88e25ba30bef7205250a4d (patch) | |
| tree | fed9e845542551131efe56718e762bf8d0b238c5 | |
| parent | e05782b8ff0fe6c45f1ff4025cdf65d67a8f6973 (diff) | |
include: lib: add a simple singly linked list implementation
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 <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
| -rw-r--r-- | include/sbi/sbi_slist.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/sbi/sbi_slist.h b/include/sbi/sbi_slist.h new file mode 100644 index 00000000..e4b83cfd --- /dev/null +++ b/include/sbi/sbi_slist.h @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Simple simply-linked list library. + * + * Copyright (c) 2025 Rivos Inc. + * + * Authors: + * Clément Léger <[email protected]> + */ + +#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 |
