| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef UTIL_LIST_H | ||
| 2 | #define UTIL_LIST_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include "macros.h" | ||
| 7 | |||
| 8 | typedef struct ListHead { | ||
| 9 | struct ListHead *next, *prev; | ||
| 10 | } ListHead; | ||
| 11 | |||
| 12 | 86 | static inline void list_init(ListHead *head) | |
| 13 | { | ||
| 14 | 86 | head->next = head; | |
| 15 | 86 | head->prev = head; | |
| 16 | 86 | } | |
| 17 | |||
| 18 | 119 | static inline void list_insert(ListHead *new, ListHead *prev, ListHead *next) | |
| 19 | { | ||
| 20 | 119 | next->prev = new; | |
| 21 | 119 | new->next = next; | |
| 22 | 119 | new->prev = prev; | |
| 23 | 119 | prev->next = new; | |
| 24 | 119 | } | |
| 25 | |||
| 26 | 118 | static inline void list_insert_before(ListHead *new, ListHead *item) | |
| 27 | { | ||
| 28 | 118 | list_insert(new, item->prev, item); | |
| 29 | 118 | } | |
| 30 | |||
| 31 | 1 | static inline void list_insert_after(ListHead *new, ListHead *item) | |
| 32 | { | ||
| 33 | 1 | list_insert(new, item, item->next); | |
| 34 | 1 | } | |
| 35 | |||
| 36 | 4 | static inline void list_remove(ListHead *entry) | |
| 37 | { | ||
| 38 | 4 | entry->next->prev = entry->prev; | |
| 39 | 4 | entry->prev->next = entry->next; | |
| 40 | 4 | *entry = (ListHead){NULL, NULL}; | |
| 41 | 4 | } | |
| 42 | |||
| 43 | 528 | static inline bool list_empty(const ListHead *head) | |
| 44 | { | ||
| 45 | 528 | return head->next == head; | |
| 46 | } | ||
| 47 | |||
| 48 | #endif | ||
| 49 |