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
14struct list_head {
15	struct list_head *next, *prev;
16};
17
18#define LIST_HEAD_INIT(name) { &(name), &(name) }
19
20#define INIT_LIST_HEAD(ptr) do { \
21	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
22} while (0)
23
24#if (!defined(__GNUC__) && !defined(__WATCOMC__))
25#define __inline__
26#endif
27
28/*
29 * Insert a new entry between two known consecutive entries.
30 *
31 * This is only for internal list manipulation where we know
32 * the prev/next entries already!
33 */
34static __inline__ void __list_add(struct list_head * new,
35	struct list_head * prev,
36	struct list_head * next)
37{
38	next->prev = new;
39	new->next = next;
40	new->prev = prev;
41	prev->next = new;
42}
43
44/*
45 * Insert a new entry after the specified head..
46 */
47static __inline__ void list_add(struct list_head *new, struct list_head *head)
48{
49	__list_add(new, head, head->next);
50}
51
52/*
53 * Insert a new entry at the tail
54 */
55static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
56{
57	__list_add(new, head->prev, head);
58}
59
60/*
61 * Delete a list entry by making the prev/next entries
62 * point to each other.
63 *
64 * This is only for internal list manipulation where we know
65 * the prev/next entries already!
66 */
67static __inline__ void __list_del(struct list_head * prev,
68				  struct list_head * next)
69{
70	next->prev = prev;
71	prev->next = next;
72}
73
74static __inline__ void list_del(struct list_head *entry)
75{
76	__list_del(entry->prev, entry->next);
77}
78
79static __inline__ int list_empty(struct list_head *head)
80{
81	return head->next == head;
82}
83
84/*
85 * Splice in "list" into "head"
86 */
87static __inline__ void list_splice(struct list_head *list, struct list_head *head)
88{
89	struct list_head *first = list->next;
90
91	if (first != list) {
92		struct list_head *last = list->prev;
93		struct list_head *at = head->next;
94
95		first->prev = head;
96		head->next = first;
97
98		last->next = at;
99		at->prev = last;
100	}
101}
102
103#define list_entry(ptr, type, member) \
104	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
105
106#define list_for_each(pos, head) \
107        for (pos = (head)->next; pos != (head); pos = pos->next)
108
109#endif
110