1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * Copyright (C) 2020-2021 Paul Cercueil <paul@crapouillou.net>
6 #ifndef __LIGHTREC_SLIST_H__
7 #define __LIGHTREC_SLIST_H__
9 #define container_of(ptr, type, member) \
10 ((type *)((void *)(ptr) - offsetof(type, member)))
13 struct slist_elm *next;
16 static inline void slist_init(struct slist_elm *head)
21 static inline struct slist_elm * slist_first(struct slist_elm *head)
26 static inline _Bool slist_empty(const struct slist_elm *head)
28 return head->next == NULL;
31 static inline void slist_remove_next(struct slist_elm *elm)
34 elm->next = elm->next->next;
37 static inline void slist_remove(struct slist_elm *head, struct slist_elm *elm)
39 struct slist_elm *prev;
41 if (head->next == elm) {
42 head->next = elm->next;
44 for (prev = head->next; prev && prev->next != elm; )
47 slist_remove_next(prev);
51 static inline void slist_append(struct slist_elm *head, struct slist_elm *elm)
53 elm->next = head->next;
57 #endif /* __LIGHTREC_SLIST_H__ */