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