-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
73 lines (58 loc) · 1.59 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
/*
* Basic double-linked list library. Borrowed fro the Linux kernel source code.
* Some things unnecessary for the goals of the project had been removed.
*/
#ifndef __LIST_H__
#define __LIST_H__
struct ListHead {
struct ListHead *next;
struct ListHead *prev;
};
#define LISTPOISON1 ((void *) 0xDEADBEEF)
#define LISTPOISON2 ((void *) 0xDEADBABA)
#define LISTHEADINIT(name) { &(name), &(name) }
#define LISTHEAD(name) \
struct ListHead name = LISTHEADINIT(name)
static inline void INITLISTHEAD(struct ListHead *list)
{
list->next = list;
list->prev = list;
}
static inline void __listadd(struct ListHead *new, struct ListHead *prev,
struct ListHead *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
static inline void listadd(struct ListHead *new, struct ListHead *head)
{
__listadd(new, head, head->next);
}
static inline void listaddtail(struct ListHead *new, struct ListHead *head)
{
__listadd(new, head->prev, head);
}
static inline void __listdel(struct ListHead *prev, struct ListHead *next)
{
next->prev = prev;
prev->next = next;
}
static inline void listdel(struct ListHead *entry)
{
__listdel(entry->prev, entry->next);
entry->next = LISTPOISON1;
entry->prev = LISTPOISON2;
}
static inline int listempty(const struct ListHead *head)
{
return head->next == head;
}
#define containerof(ptr, type, member) \
(type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member))
#define listentry(ptr, type, member) \
containerof(ptr, type, member)
#define listforeach(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#endif