~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/include/dbllnklst.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-30 12:56:49 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730125649-97sfj5li8axiseoo
Tags: 2009.07.22-179896-2
* Temporarily building without dumbnet, the recently uploaded
  new dumbnet upstream version broke down (Closes: #539006).
* Using more common name to store local debian additions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
#ifndef _DBLLNKLST_H_
68
68
#define _DBLLNKLST_H_
69
69
 
70
 
#include "vm_basic_types.h"
71
 
 
72
70
#define INCLUDE_ALLOW_MODULE
73
71
#define INCLUDE_ALLOW_USERLEVEL
74
72
#include "includeCheck.h"
75
73
 
 
74
#include "vm_basic_types.h"
 
75
 
76
76
 
77
77
#define DblLnkLst_OffsetOf(type, field) ((intptr_t)&((type *)0)->field)
78
78
 
79
79
#define DblLnkLst_Container(addr, type, field) \
80
 
   ((type *)((char *)addr - DblLnkLst_OffsetOf(type, field)))
 
80
   ((type *)((char *)(addr) - DblLnkLst_OffsetOf(type, field)))
81
81
 
82
82
#define DblLnkLst_ForEach(curr, head)                   \
83
83
      for (curr = (head)->next; curr != (head); curr = (curr)->next)
94
94
} DblLnkLst_Links;
95
95
 
96
96
 
97
 
/* Functions for both circular and anchored lists. --hpreg */
98
 
 
99
 
void DblLnkLst_Init(DblLnkLst_Links *l);
100
 
void DblLnkLst_Link(DblLnkLst_Links *l1, DblLnkLst_Links *l2);
101
 
void DblLnkLst_Unlink(DblLnkLst_Links *l1, DblLnkLst_Links *l2);
102
 
void DblLnkLst_Unlink1(DblLnkLst_Links *l);
103
 
Bool DblLnkLst_IsLinked(DblLnkLst_Links const *l);
104
 
 
105
 
/* Functions specific to anchored lists. --hpreg */
106
 
 
107
 
void DblLnkLst_LinkFirst(DblLnkLst_Links *head, DblLnkLst_Links *l);
108
 
void DblLnkLst_LinkLast(DblLnkLst_Links *head, DblLnkLst_Links *l);
 
97
/*
 
98
 * Functions
 
99
 *
 
100
 * DblLnkLst_LinkFirst and DblLnkLst_LinkLast are specific
 
101
 * to anchored lists.  The rest are for both circular and
 
102
 * anchored lists.
 
103
 */
 
104
 
 
105
 
 
106
/*
 
107
 *----------------------------------------------------------------------
 
108
 *
 
109
 * DblLnkLst_Init --
 
110
 *
 
111
 *    Initialize a member of a doubly linked list
 
112
 *
 
113
 * Result
 
114
 *    None
 
115
 *
 
116
 * Side effects:
 
117
 *    None
 
118
 *
 
119
 *----------------------------------------------------------------------
 
120
 */
 
121
 
 
122
static INLINE void
 
123
DblLnkLst_Init(DblLnkLst_Links *l) // IN
 
124
{
 
125
   l->prev = l->next = l;
 
126
}
 
127
 
 
128
 
 
129
/*
 
130
 *----------------------------------------------------------------------
 
131
 *
 
132
 * DblLnkLst_Link --
 
133
 *
 
134
 *    Merge two doubly linked lists into one
 
135
 *
 
136
 *    The operation is commutative
 
137
 *    The operation is inversible (its inverse is DblLnkLst_Unlink)
 
138
 *
 
139
 * Result
 
140
 *    None
 
141
 *
 
142
 * Side effects:
 
143
 *    None
 
144
 *
 
145
 *----------------------------------------------------------------------
 
146
 */
 
147
 
 
148
static INLINE void
 
149
DblLnkLst_Link(DblLnkLst_Links *l1, // IN
 
150
               DblLnkLst_Links *l2) // IN
 
151
{
 
152
   DblLnkLst_Links *tmp;
 
153
 
 
154
   (tmp      = l1->prev)->next = l2;
 
155
   (l1->prev = l2->prev)->next = l1;
 
156
    l2->prev = tmp                 ;
 
157
}
 
158
 
 
159
 
 
160
/*
 
161
 *----------------------------------------------------------------------
 
162
 *
 
163
 * DblLnkLst_Unlink --
 
164
 *
 
165
 *    Split one doubly linked list into two
 
166
 *
 
167
 *    No check is performed: the caller must ensure that both members
 
168
 *    belong to the same doubly linked list
 
169
 *
 
170
 *    The operation is commutative
 
171
 *    The operation is inversible (its inverse is DblLnkLst_Link)
 
172
 *
 
173
 * Result
 
174
 *    None
 
175
 *
 
176
 * Side effects:
 
177
 *    None
 
178
 *
 
179
 *----------------------------------------------------------------------
 
180
 */
 
181
 
 
182
static INLINE void
 
183
DblLnkLst_Unlink(DblLnkLst_Links *l1, // IN
 
184
                 DblLnkLst_Links *l2) // IN
 
185
{
 
186
   DblLnkLst_Links *tmp;
 
187
 
 
188
   tmp       = l1->prev            ;
 
189
   (l1->prev = l2->prev)->next = l1;
 
190
   (l2->prev = tmp     )->next = l2;
 
191
}
 
192
 
 
193
 
 
194
/*
 
195
 *----------------------------------------------------------------------
 
196
 *
 
197
 * DblLnkLst_Unlink1 --
 
198
 *
 
199
 *    Unlink an element from its list.
 
200
 *
 
201
 * Result
 
202
 *    None
 
203
 *
 
204
 * Side effects:
 
205
 *    None
 
206
 *
 
207
 *----------------------------------------------------------------------
 
208
 */
 
209
 
 
210
static INLINE void
 
211
DblLnkLst_Unlink1(DblLnkLst_Links *l) // IN
 
212
{
 
213
   DblLnkLst_Unlink(l, l->next);
 
214
}
 
215
 
 
216
 
 
217
/*
 
218
 *----------------------------------------------------------------------------
 
219
 *
 
220
 * DblLnkLst_IsLinked --
 
221
 *
 
222
 *    Determines whether an element is linked with any other elements.
 
223
 *
 
224
 * Results:
 
225
 *    TRUE if link is linked, FALSE otherwise.
 
226
 *
 
227
 * Side effects:
 
228
 *    None.
 
229
 *
 
230
 *----------------------------------------------------------------------------
 
231
 */
 
232
 
 
233
static INLINE Bool
 
234
DblLnkLst_IsLinked(DblLnkLst_Links const *l) // IN
 
235
{
 
236
   /*
 
237
    * A DblLnkLst_Links is either linked to itself (not linked) or linked to
 
238
    * other elements in a list (linked).
 
239
    */
 
240
   return l->prev != l;
 
241
}
 
242
 
 
243
 
 
244
/*
 
245
 *----------------------------------------------------------------------
 
246
 *
 
247
 * DblLnkLst_LinkFirst --
 
248
 *
 
249
 *    Insert 'l' at the beginning of the list anchored at 'head'
 
250
 *
 
251
 * Result
 
252
 *    None
 
253
 *
 
254
 * Side effects:
 
255
 *    None
 
256
 *
 
257
 *----------------------------------------------------------------------
 
258
 */
 
259
 
 
260
static INLINE void
 
261
DblLnkLst_LinkFirst(DblLnkLst_Links *head, // IN
 
262
                    DblLnkLst_Links *l)    // IN
 
263
{
 
264
   DblLnkLst_Link(head->next, l);
 
265
}
 
266
 
 
267
 
 
268
/*
 
269
 *----------------------------------------------------------------------
 
270
 *
 
271
 * DblLnkLst_LinkLast --
 
272
 *
 
273
 *    Insert 'l' at the end of the list anchored at 'head'
 
274
 *
 
275
 * Result
 
276
 *    None
 
277
 *
 
278
 * Side effects:
 
279
 *    None
 
280
 *
 
281
 *----------------------------------------------------------------------
 
282
 */
 
283
 
 
284
static INLINE void
 
285
DblLnkLst_LinkLast(DblLnkLst_Links *head, // IN
 
286
                   DblLnkLst_Links *l)    // IN
 
287
{
 
288
   DblLnkLst_Link(head, l);
 
289
}
109
290
 
110
291
 
111
292
#endif /* _DBLLNKLST_H_ */