debuggers.hg

view tools/blktap/lib/list.h @ 16564:1b863ae2bf1e

blktap: cleanups for *BSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 05 09:59:23 2007 +0000 (2007-12-05)
parents 2937703f0ed0
children
line source
1 /*
2 * list.h
3 *
4 * This is a subset of linux's list.h intended to be used in user-space.
5 *
6 */
8 #ifndef __LIST_H__
9 #define __LIST_H__
11 #ifdef LIST_HEAD
12 #undef LIST_HEAD
13 #endif
15 #define LIST_POISON1 ((void *) 0x00100100)
16 #define LIST_POISON2 ((void *) 0x00200200)
18 struct list_head {
19 struct list_head *next, *prev;
20 };
22 #define LIST_HEAD_INIT(name) { &(name), &(name) }
24 #define LIST_HEAD(name) \
25 struct list_head name = LIST_HEAD_INIT(name)
27 static inline void __list_add(struct list_head *new,
28 struct list_head *prev,
29 struct list_head *next)
30 {
31 next->prev = new;
32 new->next = next;
33 new->prev = prev;
34 prev->next = new;
35 }
37 static inline void list_add(struct list_head *new, struct list_head *head)
38 {
39 __list_add(new, head, head->next);
40 }
41 static inline void __list_del(struct list_head * prev, struct list_head * next)
42 {
43 next->prev = prev;
44 prev->next = next;
45 }
46 static inline void list_del(struct list_head *entry)
47 {
48 __list_del(entry->prev, entry->next);
49 entry->next = LIST_POISON1;
50 entry->prev = LIST_POISON2;
51 }
52 #define list_entry(ptr, type, member) \
53 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
54 #define list_for_each_entry(pos, head, member) \
55 for (pos = list_entry((head)->next, typeof(*pos), member); \
56 &pos->member != (head); \
57 pos = list_entry(pos->member.next, typeof(*pos), member))
59 #endif /* __LIST_H__ */