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