2 * Copyright (C) 2020 Paul Cercueil <paul@crapouillou.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 #ifndef __LIGHTREC_SLIST_H__
16 #define __LIGHTREC_SLIST_H__
18 #define container_of(ptr, type, member) \
19 ((type *)((void *)(ptr) - offsetof(type, member)))
22 struct slist_elm *next;
25 static inline void slist_init(struct slist_elm *head)
30 static inline struct slist_elm * slist_first(struct slist_elm *head)
35 static inline _Bool slist_empty(const struct slist_elm *head)
37 return head->next == NULL;
40 static inline void slist_remove_next(struct slist_elm *elm)
43 elm->next = elm->next->next;
46 static inline void slist_remove(struct slist_elm *head, struct slist_elm *elm)
48 struct slist_elm *prev;
50 if (head->next == elm) {
51 head->next = elm->next;
53 for (prev = head->next; prev && prev->next != elm; )
56 slist_remove_next(prev);
60 static inline void slist_append(struct slist_elm *head, struct slist_elm *elm)
62 elm->next = head->next;
66 #endif /* __LIGHTREC_SLIST_H__ */