Staging: hv: remove function pointer typedefs from vmbus.h
[safe/jmp/linux-2.6] / drivers / staging / hv / List.h
1 /*
2  *
3  * Copyright (c) 2009, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *
22  */
23
24
25 #ifndef _LIST_H_
26 #define _LIST_H_
27
28 /*
29  *
30  *  Doubly-linked list manipulation routines.  Implemented as macros
31  *  but logically these are procedures.
32  *
33  */
34
35 typedef struct _LIST_ENTRY {
36         struct _LIST_ENTRY *Flink;
37         struct _LIST_ENTRY *Blink;
38 } LIST_ENTRY, *PLIST_ENTRY;
39
40 /*
41  *  void
42  *  InitializeListHead(
43  *      PLIST_ENTRY ListHead
44  *      );
45  */
46 #define INITIALIZE_LIST_HEAD    InitializeListHead
47
48 #define InitializeListHead(ListHead) (\
49     (ListHead)->Flink = (ListHead)->Blink = (ListHead))
50
51
52 /*
53  *  bool
54  *  IsListEmpty(
55  *      PLIST_ENTRY ListHead
56  *      );
57  */
58 #define IS_LIST_EMPTY                   IsListEmpty
59
60 #define IsListEmpty(ListHead) \
61     ((ListHead)->Flink == (ListHead))
62
63
64 /*
65  *  PLIST_ENTRY
66  *  NextListEntry(
67  *      PLIST_ENTRY Entry
68  *      );
69  */
70 #define NEXT_LIST_ENTRY                 NextListEntry
71
72 #define NextListEntry(Entry) \
73     (Entry)->Flink
74
75
76 /*
77  *  PLIST_ENTRY
78  *  PrevListEntry(
79  *      PLIST_ENTRY Entry
80  *      );
81  */
82 #define PREV_LIST_ENTRY                 PrevListEntry
83
84 #define PrevListEntry(Entry) \
85     (Entry)->Blink
86
87
88 /*
89  *  PLIST_ENTRY
90  *  TopListEntry(
91  *      PLIST_ENTRY ListHead
92  *      );
93  */
94 #define TOP_LIST_ENTRY                  TopListEntry
95
96 #define TopListEntry(ListHead) \
97     (ListHead)->Flink
98
99
100
101 /*
102  *  PLIST_ENTRY
103  *  RemoveHeadList(
104  *      PLIST_ENTRY ListHead
105  *      );
106  */
107
108 #define REMOVE_HEAD_LIST                RemoveHeadList
109
110 #define RemoveHeadList(ListHead) \
111     (ListHead)->Flink;\
112     {RemoveEntryList((ListHead)->Flink)}
113
114
115 /*
116  *  PLIST_ENTRY
117  *  RemoveTailList(
118  *      PLIST_ENTRY ListHead
119  *      );
120  */
121 #define REMOVE_TAIL_LIST                RemoveTailList
122
123 #define RemoveTailList(ListHead) \
124     (ListHead)->Blink;\
125     {RemoveEntryList((ListHead)->Blink)}
126
127
128 /*
129  *  void
130  *  RemoveEntryList(
131  *      PLIST_ENTRY Entry
132  *      );
133  */
134 #define REMOVE_ENTRY_LIST               RemoveEntryList
135
136 #define RemoveEntryList(Entry) {\
137     PLIST_ENTRY _EX_Flink = (Entry)->Flink;\
138     PLIST_ENTRY _EX_Blink = (Entry)->Blink;\
139     _EX_Blink->Flink = _EX_Flink;\
140     _EX_Flink->Blink = _EX_Blink;\
141         }
142
143
144 /*
145  *  void
146  *  AttachList(
147  *      PLIST_ENTRY ListHead,
148  *      PLIST_ENTRY ListEntry
149  *      );
150  */
151 #define ATTACH_LIST             AttachList
152
153 #define AttachList(ListHead,ListEntry) {\
154     PLIST_ENTRY _EX_ListHead = (ListHead);\
155     PLIST_ENTRY _EX_Blink = (ListHead)->Blink;\
156     (ListEntry)->Blink->Flink = _EX_ListHead;\
157     _EX_Blink->Flink = (ListEntry);\
158     _EX_ListHead->Blink = (ListEntry)->Blink;\
159     (ListEntry)->Blink = _EX_Blink;\
160     }
161
162
163
164 /*
165  *  void
166  *  InsertTailList(
167  *      PLIST_ENTRY ListHead,
168  *      PLIST_ENTRY Entry
169  *      );
170  */
171
172 #define INSERT_TAIL_LIST                InsertTailList
173
174 #define InsertTailList(ListHead,Entry) {\
175     PLIST_ENTRY _EX_ListHead = (ListHead);\
176     PLIST_ENTRY _EX_Blink = (ListHead)->Blink;\
177     (Entry)->Flink = _EX_ListHead;\
178     (Entry)->Blink = _EX_Blink;\
179     _EX_Blink->Flink = (Entry);\
180     _EX_ListHead->Blink = (Entry);\
181     }
182
183
184 /*
185  *  void
186  *  InsertHeadList(
187  *      PLIST_ENTRY ListHead,
188  *      PLIST_ENTRY Entry
189  *      );
190  */
191 #define INSERT_HEAD_LIST                InsertHeadList
192
193 #define InsertHeadList(ListHead,Entry) {\
194     PLIST_ENTRY _EX_ListHead = (ListHead);\
195     PLIST_ENTRY _EX_Flink = (ListHead)->Flink;\
196     (Entry)->Flink = _EX_Flink;\
197     (Entry)->Blink = _EX_ListHead;\
198     _EX_Flink->Blink = (Entry);\
199     _EX_ListHead->Flink = (Entry);\
200     }
201
202
203 /*
204  *  void
205  *  IterateListEntries(
206  *      PLIST_ENTRY anchor,
207  *      PLIST_ENTRY index,
208  *              PLIST_ENTRY listp
209  *      );
210  */
211
212 #define ITERATE_LIST_ENTRIES    IterateListEntries
213
214 #define IterateListEntries(anchor, index, listp) \
215         (anchor) = (LIST_ENTRY *)(listp); \
216         for((index) = (anchor)->Flink; (index) != (anchor); (index) = (index)->Flink)
217
218
219
220 /*
221  *  PSINGLE_LIST_ENTRY
222  *  PopEntryList(
223  *      PSINGLE_LIST_ENTRY ListHead
224  *      );
225  */
226
227 #define POP_ENTRY_LIST          PopEntryList
228
229 #define PopEntryList(ListHead) \
230     (ListHead)->Next;\
231     {\
232         PSINGLE_LIST_ENTRY FirstEntry;\
233         FirstEntry = (ListHead)->Next;\
234         if (FirstEntry != NULL) {     \
235             (ListHead)->Next = FirstEntry->Next;\
236         }                             \
237     }
238
239
240
241 /*
242  *  void
243  *  PushEntryList(
244  *      PSINGLE_LIST_ENTRY ListHead,
245  *              PSINGLE_LIST_ENTRY Entry
246  *      );
247  */
248
249 #define PUSH_ENTRY_LIST                 PushEntryList
250
251 #define PushEntryList(ListHead,Entry) \
252     (Entry)->Next = (ListHead)->Next; \
253     (ListHead)->Next = (Entry)
254
255 #ifndef CONTAINING_RECORD
256 #define CONTAINING_RECORD(address, type, field) ((type *)( \
257                                                   (char *)(address) - \
258                                                   (char *)(&((type *)0)->field)))
259 #endif /* CONTAINING_RECORD */
260
261 #endif /* _LIST_H_ */
262
263 /* EOF */