-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.h
63 lines (40 loc) · 985 Bytes
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef LIST_H
#define LIST_H
#define INLINE static
typedef struct LIST {
struct LIST *next;
struct LIST *previous;
} LIST;
#define list_entry(node, type, member) ((type *)((U8 *)(node) - (U32)(&((type *)0)->member)))
INLINE void list_init(LIST *list_head)
{
list_head->next = list_head;
list_head->previous = list_head;
}
INLINE unsigned char is_list_empty(LIST *list)
{
return (list->next == list);
}
INLINE void list_insert(LIST *head, LIST *element)
{
element->previous= head;
element->next =element;
head->next = element;
#if 0
element->next = head->next;
element->previous = head;
head->next->previous = element;
head->next = element;
#endif
}
INLINE int list_delete(LIST *element)
{
if (is_list_empty(element))
{
element->previous->next = element->previous;
return 0;
}
element->previous->next = element->next;
element->next->previous = element->previous;
}
#endif