summaryrefslogtreecommitdiffstats
path: root/lib/list/list.h
blob: f78411ea18f7679e058dfaa1f4f6ebb987cc582c (plain)
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
#ifndef _LIST_H
#define _LIST_H

struct list_item {
	struct list_item *prev, *next;
};

struct list {
	struct list_item head;
};

#ifndef container_of
#define container_of(ptr, type, member) ({			\
	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
	(type *)( (char *)__mptr - offsetof(type,member) );})
#endif

#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

#define list_for_each(list, pos) \
	for (pos = (list)->head.next; pos != ((list)->head); pos = pos->next)

#define list_entry(ptr, type, member) \
	container_of(ptr, type, member)

#define list_for_each_entry(list, pos, member)				\
	for (pos = list_entry((list)->head.next, typeof(*pos), member);	\
	     &pos->member != &(list)->head; 	\
	     pos = list_entry(pos->member.next, typeof(*pos), member))

#define list_for_each_entry_safe(list, pos, n, member)			\
	for (pos = list_entry((list)->head.next, typeof(*pos), member),	\
		n = list_entry(pos->member.next, typeof(*pos), member);	\
	     &pos->member != &(list)->head;				\
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))


void list_init(struct list *list);

void list_add(struct list *list, struct list_item *item);

void list_remove(struct list_item *item);

#endif /* _LIST_H */
OpenPOWER on IntegriCloud