[3320] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | #ifndef LINUX_LIST_H
|
---|
| 3 | #define LINUX_LIST_H 1
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
| 6 | * Simple doubly linked list implementation.
|
---|
| 7 | *
|
---|
| 8 | * Some of the internal functions ("__xxx") are useful when
|
---|
| 9 | * manipulating whole lists rather than single entries, as
|
---|
| 10 | * sometimes we already know the next/prev entries and we can
|
---|
| 11 | * generate better code by using them directly rather than
|
---|
| 12 | * using the generic single-entry routines.
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | struct list_head {
|
---|
| 16 | struct list_head *next, *prev;
|
---|
| 17 | };
|
---|
| 18 |
|
---|
| 19 | #define LIST_HEAD_INIT(name) { &(name), &(name) }
|
---|
| 20 |
|
---|
| 21 | #define LIST_HEAD(name) \
|
---|
| 22 | struct list_head name = { &name, &name }
|
---|
| 23 |
|
---|
| 24 | #define INIT_LIST_HEAD(ptr) do { \
|
---|
| 25 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
---|
| 26 | } while (0)
|
---|
| 27 |
|
---|
| 28 | #if (!defined(__GNUC__) && !defined(__WATCOMC__))
|
---|
| 29 | #define __inline__
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | /*
|
---|
| 33 | * Insert a new entry between two known consecutive entries.
|
---|
| 34 | *
|
---|
| 35 | * This is only for internal list manipulation where we know
|
---|
| 36 | * the prev/next entries already!
|
---|
| 37 | */
|
---|
| 38 | static __inline__ void __list_add(struct list_head * new,
|
---|
| 39 | struct list_head * prev,
|
---|
| 40 | struct list_head * next)
|
---|
| 41 | {
|
---|
| 42 | next->prev = new;
|
---|
| 43 | new->next = next;
|
---|
| 44 | new->prev = prev;
|
---|
| 45 | prev->next = new;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /*
|
---|
| 49 | * Insert a new entry after the specified head..
|
---|
| 50 | */
|
---|
| 51 | static __inline__ void list_add(struct list_head *new, struct list_head *head)
|
---|
| 52 | {
|
---|
| 53 | __list_add(new, head, head->next);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | /*
|
---|
| 57 | * Insert a new entry at the tail
|
---|
| 58 | */
|
---|
| 59 | static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
|
---|
| 60 | {
|
---|
| 61 | __list_add(new, head->prev, head);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | * Delete a list entry by making the prev/next entries
|
---|
| 66 | * point to each other.
|
---|
| 67 | *
|
---|
| 68 | * This is only for internal list manipulation where we know
|
---|
| 69 | * the prev/next entries already!
|
---|
| 70 | */
|
---|
| 71 | static __inline__ void __list_del(struct list_head * prev,
|
---|
| 72 | struct list_head * next)
|
---|
| 73 | {
|
---|
| 74 | next->prev = prev;
|
---|
| 75 | prev->next = next;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | static __inline__ void list_del(struct list_head *entry)
|
---|
| 79 | {
|
---|
| 80 | __list_del(entry->prev, entry->next);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | static __inline__ int list_empty(struct list_head *head)
|
---|
| 84 | {
|
---|
| 85 | return head->next == head;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * Splice in "list" into "head"
|
---|
| 90 | */
|
---|
| 91 | static __inline__ void list_splice(struct list_head *list, struct list_head *head)
|
---|
| 92 | {
|
---|
| 93 | struct list_head *first = list->next;
|
---|
| 94 |
|
---|
| 95 | if (first != list) {
|
---|
| 96 | struct list_head *last = list->prev;
|
---|
| 97 | struct list_head *at = head->next;
|
---|
| 98 |
|
---|
| 99 | first->prev = head;
|
---|
| 100 | head->next = first;
|
---|
| 101 |
|
---|
| 102 | last->next = at;
|
---|
| 103 | at->prev = last;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | #define list_entry(ptr, type, member) \
|
---|
| 108 | ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
---|
| 109 |
|
---|
| 110 | #define list_for_each(pos, head) \
|
---|
| 111 | for (pos = (head)->next; pos != (head); pos = pos->next)
|
---|
| 112 |
|
---|
| 113 | #endif
|
---|