1 | /*************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (C) 2001 International Business Machines |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of the GPFS mmfslinux kernel module. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions |
---|
10 | * are met: |
---|
11 | * |
---|
12 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer in the |
---|
16 | * documentation and/or other materials provided with the distribution. |
---|
17 | * 3. The name of the author may not be used to endorse or promote products |
---|
18 | * derived from this software without specific prior written |
---|
19 | * permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
---|
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
---|
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
---|
27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
---|
28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
---|
30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | *************************************************************************** */ |
---|
33 | /* @(#)02 1.9 src/avs/fs/mmfs/ts/kernext/ibm-kxi/cxiLinkList.h, mmfs, avs_rgpfs24, rgpfs240610b 8/4/04 11:54:21 */ |
---|
34 | |
---|
35 | #ifndef _h_CXILINKLIST |
---|
36 | #define _h_CXILINKLIST |
---|
37 | |
---|
38 | #include <cxiSystem.h> |
---|
39 | #include <cxiTypes.h> |
---|
40 | |
---|
41 | #ifdef __cplusplus |
---|
42 | |
---|
43 | /* A double linked list element class. */ |
---|
44 | class DLink_t |
---|
45 | { |
---|
46 | public: |
---|
47 | DLink_tSXPtr nextP; |
---|
48 | DLink_tSXPtr prevP; |
---|
49 | |
---|
50 | /* The head element of the list is initialized to point to itself, |
---|
51 | * signifying no elements on the list. |
---|
52 | */ |
---|
53 | inline void init() |
---|
54 | { |
---|
55 | nextP = this; |
---|
56 | prevP = this; |
---|
57 | } |
---|
58 | |
---|
59 | DLink_t() |
---|
60 | { |
---|
61 | init(); |
---|
62 | } |
---|
63 | |
---|
64 | /* Add an element or circular linked list of elements, immediately |
---|
65 | * after this (head of the list) |
---|
66 | */ |
---|
67 | inline void enqueueHead(DLink_t *elementP) |
---|
68 | { |
---|
69 | DLink_t *saveP = elementP->prevP; |
---|
70 | |
---|
71 | saveP->nextP = nextP; |
---|
72 | nextP->prevP = saveP; |
---|
73 | elementP->prevP = this; |
---|
74 | nextP = elementP; |
---|
75 | } |
---|
76 | |
---|
77 | /* Add an element or circular linked list of elements, immediately |
---|
78 | * preceding this (tail of the list) |
---|
79 | */ |
---|
80 | inline void enqueueTail(DLink_t *elementP) |
---|
81 | { |
---|
82 | DLink_t *saveP = elementP->prevP; |
---|
83 | |
---|
84 | prevP->nextP = elementP; |
---|
85 | elementP->prevP = prevP; |
---|
86 | prevP = saveP; |
---|
87 | saveP->nextP = this; |
---|
88 | } |
---|
89 | |
---|
90 | /* Remove a single element from the linked list and |
---|
91 | * initialize it as a linked list pointing to itself |
---|
92 | */ |
---|
93 | inline DLink_t *dequeue() |
---|
94 | { |
---|
95 | prevP->nextP = nextP; |
---|
96 | nextP->prevP = prevP; |
---|
97 | init(); |
---|
98 | |
---|
99 | return this; |
---|
100 | } |
---|
101 | |
---|
102 | /* Remove the element immediately after this (head of the list) |
---|
103 | * and initialize it as a linked list pointing to itself. |
---|
104 | */ |
---|
105 | inline DLink_t *dequeueHead() |
---|
106 | { |
---|
107 | return nextP->dequeue(); |
---|
108 | } |
---|
109 | |
---|
110 | /* Remove the element immediately preceeding this (tail of the list) |
---|
111 | * and initialize it as a linked list pointing to itself. |
---|
112 | */ |
---|
113 | inline DLink_t *dequeueTail() |
---|
114 | { |
---|
115 | return prevP->dequeue(); |
---|
116 | } |
---|
117 | |
---|
118 | inline Boolean isEmpty() |
---|
119 | { |
---|
120 | return (nextP == this); |
---|
121 | } |
---|
122 | |
---|
123 | inline DLink_t *next() |
---|
124 | { |
---|
125 | return nextP; |
---|
126 | } |
---|
127 | |
---|
128 | inline DLink_t *prev() |
---|
129 | { |
---|
130 | return prevP; |
---|
131 | } |
---|
132 | |
---|
133 | inline DLink_t *head() |
---|
134 | { |
---|
135 | return nextP; |
---|
136 | } |
---|
137 | |
---|
138 | inline DLink_t *tail() |
---|
139 | { |
---|
140 | return prevP; |
---|
141 | } |
---|
142 | }; |
---|
143 | |
---|
144 | #else |
---|
145 | |
---|
146 | /* The same class as above, declared as a structure for C code */ |
---|
147 | struct DLink_t |
---|
148 | { |
---|
149 | /* Use standard pointers here for the portability layer / kernel. */ |
---|
150 | struct DLink_t *nextP; |
---|
151 | struct DLink_t *prevP; |
---|
152 | }; |
---|
153 | |
---|
154 | typedef struct DLink_t DLink_t; |
---|
155 | #endif /* __cplusplus */ |
---|
156 | |
---|
157 | |
---|
158 | /* Inline functions mimic'ing the class members of the DLink class. |
---|
159 | * Can be used in either C or C++ code. |
---|
160 | */ |
---|
161 | static inline void |
---|
162 | DLinkInit(DLink_t *thisP) |
---|
163 | { |
---|
164 | thisP->nextP = thisP; |
---|
165 | thisP->prevP = thisP; |
---|
166 | } |
---|
167 | |
---|
168 | /* Add an element or circular linked list of elements, immediately |
---|
169 | * after this (head of the list) |
---|
170 | */ |
---|
171 | static inline void |
---|
172 | DLinkEnqueueHead(DLink_t *thisP, DLink_t *elementP) |
---|
173 | { |
---|
174 | DLink_t *saveP = elementP->prevP; |
---|
175 | |
---|
176 | saveP->nextP = thisP->nextP; |
---|
177 | thisP->nextP->prevP = saveP; |
---|
178 | elementP->prevP = thisP; |
---|
179 | thisP->nextP = elementP; |
---|
180 | } |
---|
181 | |
---|
182 | /* Add an element or circular linked list of elements, immediately |
---|
183 | * preceding this (tail of the list) |
---|
184 | */ |
---|
185 | static inline void |
---|
186 | DLinkEnqueueTail(DLink_t *thisP, DLink_t *elementP) |
---|
187 | { |
---|
188 | DLink_t *saveP = elementP->prevP; |
---|
189 | |
---|
190 | thisP->prevP->nextP = elementP; |
---|
191 | elementP->prevP = thisP->prevP; |
---|
192 | thisP->prevP = saveP; |
---|
193 | saveP->nextP = thisP; |
---|
194 | } |
---|
195 | |
---|
196 | /* Remove a single element from the linked list and |
---|
197 | * initialize it as a linked list pointing to itself |
---|
198 | */ |
---|
199 | static inline DLink_t * |
---|
200 | DLinkDequeue(DLink_t *thisP) |
---|
201 | { |
---|
202 | thisP->prevP->nextP = thisP->nextP; |
---|
203 | thisP->nextP->prevP = thisP->prevP; |
---|
204 | DLinkInit(thisP); |
---|
205 | |
---|
206 | return thisP; |
---|
207 | } |
---|
208 | |
---|
209 | /* Remove the element immediately after this (head of the list) |
---|
210 | * and initialize it as a linked list pointing to itself. |
---|
211 | */ |
---|
212 | static inline DLink_t * |
---|
213 | DLinkDequeueHead(DLink_t *thisP) |
---|
214 | { |
---|
215 | return DLinkDequeue(thisP->nextP); |
---|
216 | } |
---|
217 | |
---|
218 | /* Remove the element immediately preceeding this (tail of the list) |
---|
219 | * and initialize it as a linked list pointing to itself. |
---|
220 | */ |
---|
221 | static inline DLink_t * |
---|
222 | DLinkDequeueTail(DLink_t *thisP) |
---|
223 | { |
---|
224 | return DLinkDequeue(thisP->prevP); |
---|
225 | } |
---|
226 | |
---|
227 | static inline Boolean |
---|
228 | DLinkIsEmpty(DLink_t *thisP) |
---|
229 | { |
---|
230 | return (thisP->nextP == thisP); |
---|
231 | } |
---|
232 | |
---|
233 | /* Given a class type, a pointer to the class member, and the |
---|
234 | * member name, return a pointer to the base class. |
---|
235 | */ |
---|
236 | #define MemberToClass(CLASSTYPE, PTRMEMBER, MEMBERNAME) \ |
---|
237 | (CLASSTYPE *)(((char *)PTRMEMBER) - OFFSET_OF(MEMBERNAME, CLASSTYPE)) |
---|
238 | |
---|
239 | #endif /* _h_CXILINKLIST */ |
---|