• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/netatalk-2.2.0/include/atalk/
1/* This code has been stolen from Linux kernel :) */
2/* distributed under GNU GPL version 2. */
3
4#ifndef _ATALK_LIST_H
5#define _ATALK_LIST_H
6
7/*
8 * Simple doubly linked list implementation.
9 *
10 * Some of the internal functions ("__xxx") are useful when
11 * manipulating whole lists rather than single entries, as
12 * sometimes we already know the next/prev entries and we can
13 * generate better code by using them directly rather than
14 * using the generic single-entry routines.
15 */
16
17struct list_head {
18    struct list_head *next, *prev;
19};
20
21#define ATALK_LIST_HEAD_INIT(name) { &(name), &(name) }
22
23#define ATALK_LIST_HEAD(name) \
24    struct list_head name = ATALK_LIST_HEAD_INIT(name)
25
26#define ATALK_INIT_LIST_HEAD(ptr) do { \
27    (ptr)->next = (ptr); (ptr)->prev = (ptr); \
28} while (0)
29
30#ifdef USE_LIST
31/*
32 * Insert a new entry between two known consecutive entries.
33 *
34 * This is only for internal list manipulation where we know
35 * the prev/next entries already!
36 */
37static inline void __list_add(struct list_head * new,
38                                  struct list_head * prev,
39                                  struct list_head * next)
40{
41    next->prev = new;
42    new->next = next;
43    new->prev = prev;
44    prev->next = new;
45}
46
47/**
48 * list_add - add a new entry
49 * @new: new entry to be added
50 * @head: list head to add it after
51 *
52 * Insert a new entry after the specified head.
53 * This is good for implementing stacks.
54 */
55static inline void list_add(struct list_head *new, struct list_head *head)
56{
57    __list_add(new, head, head->next);
58}
59
60/**
61 * list_add_tail - add a new entry
62 * @new: new entry to be added
63 * @head: list head to add it before
64 *
65 * Insert a new entry before the specified head.
66 * This is useful for implementing queues.
67 */
68static inline void list_add_tail(struct list_head *new, struct list_head *head)
69{
70    __list_add(new, head->prev, head);
71}
72
73/*
74 * Delete a list entry by making the prev/next entries
75 * point to each other.
76 *
77 * This is only for internal list manipulation where we know
78 * the prev/next entries already!
79 */
80static inline void __list_del(struct list_head * prev,
81                                  struct list_head * next)
82{
83    next->prev = prev;
84    prev->next = next;
85}
86
87/**
88 * list_del - deletes entry from list.
89 * @entry: the element to delete from the list.
90 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
91 */
92static inline void list_del(struct list_head *entry)
93{
94    __list_del(entry->prev, entry->next);
95}
96
97/**
98 * list_del_init - deletes entry from list and reinitialize it.
99 * @entry: the element to delete from the list.
100 */
101static inline void list_del_init(struct list_head *entry)
102{
103    __list_del(entry->prev, entry->next);
104    ATALK_INIT_LIST_HEAD(entry);
105}
106
107/**
108 * list_empty - tests whether a list is empty
109 * @head: the list to test.
110 */
111static inline int list_empty(struct list_head *head)
112{
113    return head->next == head;
114}
115
116/**
117 * list_splice - join two lists
118 * @list: the new list to add.
119 * @head: the place to add it in the first list.
120 */
121static inline void list_splice(struct list_head *list, struct list_head *head)
122{
123    struct list_head *first = list->next;
124
125    if (first != list) {
126        struct list_head *last = list->prev;
127        struct list_head *at = head->next;
128
129        first->prev = head;
130        head->next = first;
131
132        last->next = at;
133        at->prev = last;
134    }
135}
136
137#endif
138/**
139 * list_entry - get the struct for this entry
140 * @ptr:	the &struct list_head pointer.
141 * @type:	the type of the struct this is embedded in.
142 * @member:	the name of the list_struct within the struct.
143 */
144#define list_entry(ptr, type, member) \
145    ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
146
147/**
148 * list_for_each	-	iterate over a list
149 * @pos:	the &struct list_head to use as a loop counter.
150 * @n:		another &struct list_head to use as temporary storage
151 * @head:	the head for your list.
152 */
153#define list_for_each(pos, head) \
154    for (pos = (head)->next; pos != (head); \
155        pos = pos->next)
156
157/**
158 * list_for_each_prev	-	iterate over a list in reverse order
159 * @pos:	the &struct list_head to use as a loop counter.
160 * @head:	the head for your list.
161 */
162#define list_for_each_prev(pos, head) \
163    for (pos = (head)->prev; pos != (head); \
164        pos = pos->prev)
165#endif
166