1 | /* vi: set sw=4 ts=4: */
|
---|
2 | #if !defined(_BLKID_LIST_H) && !defined(LIST_HEAD)
|
---|
3 | #define BLKID_LIST_H 1
|
---|
4 |
|
---|
5 | #ifdef __cplusplus
|
---|
6 | extern "C" {
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Simple doubly linked list implementation.
|
---|
11 | *
|
---|
12 | * Some of the internal functions ("__xxx") are useful when
|
---|
13 | * manipulating whole lists rather than single entries, as
|
---|
14 | * sometimes we already know the next/prev entries and we can
|
---|
15 | * generate better code by using them directly rather than
|
---|
16 | * using the generic single-entry routines.
|
---|
17 | */
|
---|
18 |
|
---|
19 | struct list_head {
|
---|
20 | struct list_head *next, *prev;
|
---|
21 | };
|
---|
22 |
|
---|
23 | #define LIST_HEAD_INIT(name) { &(name), &(name) }
|
---|
24 |
|
---|
25 | #define LIST_HEAD(name) \
|
---|
26 | struct list_head name = LIST_HEAD_INIT(name)
|
---|
27 |
|
---|
28 | #define INIT_LIST_HEAD(ptr) do { \
|
---|
29 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
---|
30 | } while (0)
|
---|
31 |
|
---|
32 | void __list_add(struct list_head * add, struct list_head * prev, struct list_head * next);
|
---|
33 | void list_add(struct list_head *add, struct list_head *head);
|
---|
34 | void list_add_tail(struct list_head *add, struct list_head *head);
|
---|
35 | void __list_del(struct list_head * prev, struct list_head * next);
|
---|
36 | void list_del(struct list_head *entry);
|
---|
37 | void list_del_init(struct list_head *entry);
|
---|
38 | int list_empty(struct list_head *head);
|
---|
39 | void list_splice(struct list_head *list, struct list_head *head);
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * list_entry - get the struct for this entry
|
---|
43 | * @ptr: the &struct list_head pointer.
|
---|
44 | * @type: the type of the struct this is embedded in.
|
---|
45 | * @member: the name of the list_struct within the struct.
|
---|
46 | */
|
---|
47 | #define list_entry(ptr, type, member) \
|
---|
48 | ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * list_for_each - iterate over elements in a list
|
---|
52 | * @pos: the &struct list_head to use as a loop counter.
|
---|
53 | * @head: the head for your list.
|
---|
54 | */
|
---|
55 | #define list_for_each(pos, head) \
|
---|
56 | for (pos = (head)->next; pos != (head); pos = pos->next)
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * list_for_each_safe - iterate over elements in a list, but don't dereference
|
---|
60 | * pos after the body is done (in case it is freed)
|
---|
61 | * @pos: the &struct list_head to use as a loop counter.
|
---|
62 | * @pnext: the &struct list_head to use as a pointer to the next item.
|
---|
63 | * @head: the head for your list (not included in iteration).
|
---|
64 | */
|
---|
65 | #define list_for_each_safe(pos, pnext, head) \
|
---|
66 | for (pos = (head)->next, pnext = pos->next; pos != (head); \
|
---|
67 | pos = pnext, pnext = pos->next)
|
---|
68 |
|
---|
69 | #ifdef __cplusplus
|
---|
70 | }
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | #endif
|
---|