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__
11 #define container_of(ptr, type, member) \
12 ((type *)((void *)(ptr) - offsetof(type, member)))
15 struct slist_elm *next;
18 static inline void slist_init(struct slist_elm *head)
23 static inline struct slist_elm * slist_first(struct slist_elm *head)
28 static inline _Bool slist_empty(const struct slist_elm *head)
30 return head->next == NULL;
33 static inline void slist_remove_next(struct slist_elm *elm)
36 elm->next = elm->next->next;
39 static inline void slist_remove(struct slist_elm *head, struct slist_elm *elm)
41 struct slist_elm *prev;
43 if (head->next == elm) {
44 head->next = elm->next;
46 for (prev = head->next; prev && prev->next != elm; )
49 slist_remove_next(prev);
53 static inline void slist_append(struct slist_elm *head, struct slist_elm *elm)
55 elm->next = head->next;
59 #endif /* __LIGHTREC_SLIST_H__ */