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