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 |
|
76 |
static inline void list_init(ListHead *head) |
13 |
|
|
{ |
14 |
|
76 |
head->next = head; |
15 |
|
76 |
head->prev = head; |
16 |
|
76 |
} |
17 |
|
|
|
18 |
|
109 |
static inline void list_insert(ListHead *new, ListHead *prev, ListHead *next) |
19 |
|
|
{ |
20 |
|
109 |
next->prev = new; |
21 |
|
109 |
new->next = next; |
22 |
|
109 |
new->prev = prev; |
23 |
|
109 |
prev->next = new; |
24 |
|
109 |
} |
25 |
|
|
|
26 |
|
108 |
static inline void list_insert_before(ListHead *new, ListHead *item) |
27 |
|
|
{ |
28 |
|
108 |
list_insert(new, item->prev, item); |
29 |
|
108 |
} |
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 |
|
355 |
static inline bool list_empty(const ListHead *head) |
44 |
|
|
{ |
45 |
|
355 |
return head->next == head; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
#endif |
49 |
|
|
|