Files @ 5fc7f2080582
Branch filter:

Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public-bincomp/vmkernel64/release/lib/vmkapi_cslist.h

unknown
ESXi-5.5-U3
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/* **********************************************************
 * Copyright 2008 - 2009 VMware, Inc.  All rights reserved.
 * **********************************************************/

/*
 * @VMKAPIMOD_LICENSE@
 */

/*
 ***********************************************************************
 * CSList                                                         */ /**
 * \addtogroup Lib
 * @{
 * \defgroup CSList Counting Singly-Linked List Management
 *
 * Singly-linked lists with an element counter.
 * 
 * @{ 
 ***********************************************************************
 */

#ifndef _VMKAPI_CSLIST_H_
#define _VMKAPI_CSLIST_H_

/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */

/*
 * Structure representing the counting singly-linked list.
 */

typedef struct vmk_CSList {
   /** Underlying singly-linked list */
   vmk_SList slist;
   
   /** Current number of elements in the singly linked list */
   vmk_uint32 numElements;
} vmk_CSList;

/*
 ***********************************************************************
 * VMK_CSLIST_FORALL --                                           */ /**
 *
 * \brief for-loop replacement macro to scan through a list from
 *        the first to the last list member.
 *
 * \note Expressions that contain side effects aren't valid as 
 *       parameters (example: removal).
 *
 * \sa VMK_CSLIST_FORALL_SAFE
 *
 * \param[in]     cslist   The list to scan.
 * \param[in,out] current  Loop pointer that is updated with the current
 *                         list member each time through the loop.
 *
 ***********************************************************************
 */

#define VMK_CSLIST_FORALL(cslist, current) \
        VMK_SLIST_FORALL(&((cslist)->slist), current)

/*
 ***********************************************************************
 * VMK_CSLIST_FORALL_SAFE --                                      */ /**
 *
 * \brief for-loop replacement macro to scan through a list from
 *        the first to the last list member.
 *
 * \note This macro can be used when removal of element is needed while
 *       looping.
 *
 * \note This macro is pretty inefficient as it maintains 3 pointers
 *       per iteration and has additional comparisons to do so. In
 *       case of performance critical loops it is advisable not to use
 *       it and do the necessary bookkeeping (a subset of this)
 *       manually.
 *
 * \sa VMK_CSLIST_FORALL
 *
 * \param[in]     cslist   The list to scan.
 * \param[in,out] prev     Loop pointer that is updated each time through
 *                         the loop with the previous list member.
 * \param[in,out] current  Loop pointer that is updated each time through
 *                         the loop with the current list member.
 * \param[in,out] next     Loop pointer that is updated each time through
 *                         the loop with the next list member.
 *
 ***********************************************************************
 */

#define VMK_CSLIST_FORALL_SAFE(cslist, prev, current, next) \
        VMK_SLIST_FORALL_SAFE(&((cslist)->slist), prev, current, next)

/*
 ***********************************************************************
 * VMK_CSLIST_FORALL_AFTER --                                     */ /**
 *
 * \brief for-loop replacement macro to scan through a list from
 *        the current to the last list member.
 *
 * \note Expressions that contain side effects aren't valid as 
 *       parameters (example: removal).
 *
 * \sa VMK_CSLIST_FORALL
 * \sa VMK_CSLIST_FORALL_SAFE
 *
 * \param[in]     cslist   The list to scan.
 * \param[in,out] current  Loop pointer that indicate the element where to
 *                         start and is updated with the current list member 
 *                         each time through the loop.
 *
 ***********************************************************************
 */

#define VMK_CSLIST_FORALL_AFTER(cslist, current) \
        VMK_SLIST_FORALL_AFTER(&((cslist)->slist), current)

/*
 ***********************************************************************
 * vmk_CSListIsEmpty --                                           */ /**
 *
 * \brief Checks whether a list is empty or not.
 *
 * \param[in]  list        Target list.
 *
 * \retval     VMK_TRUE    The list is empty.
 * \retval     VMK_FALSE   The list is not empty.
 *
 ***********************************************************************
 */

static inline vmk_Bool
vmk_CSListIsEmpty(const vmk_CSList *list)
{
   VMK_ASSERT(list);
   return list->numElements == 0 ? VMK_TRUE : VMK_FALSE;
}

/*
 ***********************************************************************
 * vmk_CSListFirst --                                             */ /**
 *
 * \brief Returns the first element (head) of a list.
 *
 * \param[in]  list        Target list.
 *
 * \retval     NULL        The list is empty.
 * \return                 A pointer to the head of the list.
 *
 ***********************************************************************
 */

static inline vmk_SList_Links *
vmk_CSListFirst(const vmk_CSList *list)
{
   VMK_ASSERT(list);
   return vmk_SListFirst(&list->slist);
}

/*
 ***********************************************************************
 * vmk_CSListLast --                                              */ /**
 *
 * \brief Returns the last element (tail) of a list.
 *
 * \param[in]  list        Target list.
 *
 * \retval     NULL        The list is empty.
 * \return                 A pointer to the tail of the list.
 *
 ***********************************************************************
 */

static inline vmk_SList_Links *
vmk_CSListLast(const vmk_CSList *list)
{
   VMK_ASSERT(list);
   return vmk_SListLast(&list->slist);
}

/*
 ***********************************************************************
 * vmk_CSListPrev --                                              */ /**
 *
 * \brief Returns the previous element in a list. Runs in O(n).
 *
 * \param[in]  list        Target list.
 * \param[in]  element     Element whose previous element is asked for.
 *
 * \retval     NULL        We are at the beginning of the list.
 * \return                 A pointer to the previous element.
 *
 ***********************************************************************
 */

static inline vmk_SList_Links *
vmk_CSListPrev(const vmk_CSList *list, const vmk_SList_Links *element)
{
   VMK_ASSERT(list);
   return vmk_SListPrev(&list->slist, element);
}

/*
 ***********************************************************************
 * vmk_CSListNext --                                              */ /**
 *
 * \brief Returns the following link in a list.
 *
 * \param[in]  element     Target list.
 *
 * \retval     NULL        We are at the end of the list.
 * \return                 A pointer to the next element.
 *
 ***********************************************************************
 */

static inline vmk_SList_Links *
vmk_CSListNext(const vmk_SList_Links *element)
{
   return vmk_SListNext(element);
}

/*
 ***********************************************************************
 * vmk_CSListInit --                                              */ /**
 *
 * \brief Initializes a list to be an empty list.
 *
 * \param[in]  cslist      Target list.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListInit(vmk_CSList *cslist)
{
   VMK_ASSERT(cslist);
   vmk_SListInit(&cslist->slist);
   cslist->numElements = 0;
}

/*
 ***********************************************************************
 * vmk_CSListCount --                                             */ /**
 *
 * \brief Returns the number of element in a list.
 *
 * \param[in]  cslist      Target list.
 *
 * \return                 The number of elements in the list.
 *
 ***********************************************************************
 */

static inline vmk_uint32
vmk_CSListCount(const vmk_CSList *cslist)
{
   VMK_ASSERT(cslist);
   return cslist->numElements;
}

/*
 ***********************************************************************
 * vmk_CSListPop --                                               */ /**
 *
 * \brief Returns the first element (head) of a list and remove it
 * from the list.
 *
 * \param[in]  cslist      Target list.
 *
 * \return                 A pointer to the head of the list.
 *
 ***********************************************************************
 */

static inline vmk_SList_Links *
vmk_CSListPop(vmk_CSList *cslist)
{
   vmk_SList_Links *element;
   VMK_ASSERT(cslist);
   
   element = vmk_SListPop(&cslist->slist);
   cslist->numElements--;
   return element;
}

/*
 ***********************************************************************
 * vmk_CSListInsertAtHead --                                      */ /**
 *
 * \brief Inserts a given element at the beginning of the list.
 *
 * \param[in]  cslist      Target list.
 * \param[in]  element     Element to insert.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListInsertAtHead(vmk_CSList *cslist, vmk_SList_Links *element)
{
   VMK_ASSERT(cslist);
   vmk_SListInsertAtHead(&cslist->slist, element);
   cslist->numElements++;
}

/*
 ***********************************************************************
 * vmk_CSListInsertAtTail --                                      */ /**
 *
 * \brief Inserts a given element at the end of the list.
 *
 * \param[in]  cslist      Target list.
 * \param[in]  element     Element to insert.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListInsertAtTail(vmk_CSList *cslist, vmk_SList_Links *element)
{
   VMK_ASSERT(cslist);
   vmk_SListInsertAtTail(&cslist->slist, element);
   cslist->numElements++;
}

/*
 ***********************************************************************
 * vmk_CSListInsertAfter --                                       */ /**
 *
 * \brief Inserts an element after a given element.
 *
 * \param[in]  cslist      Target list.
 * \param[in]  element     Element to insert.
 * \param[in]  after       Element to insert the new element after.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListInsertAfter(vmk_CSList *cslist, vmk_SList_Links *element,
                      vmk_SList_Links *after)
{
   VMK_ASSERT(cslist);
   vmk_SListInsertAfter(&cslist->slist, element, after);
   cslist->numElements++;
}

/*
 ***********************************************************************
 * vmk_CSListRemove --                                            */ /**
 *
 * \brief Removes a given element from the list knowing its predecessor
 *
 * \param[in]  cslist      Target list.
 * \param[in]  element     Element to remove.
 * \param[in]  prev        Element preceding the element to remove.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListRemove(vmk_CSList *cslist, vmk_SList_Links *element,
                 vmk_SList_Links *prev)
{
   VMK_ASSERT(cslist);
   vmk_SListRemove(&cslist->slist, element, prev);
   cslist->numElements--;
}

/*
 ***********************************************************************
 * vmk_CSListRemoveSlow --                                        */ /**
 *
 * \brief Removes a given element from the list. Runs O(n).
 *
 * \param[in]  cslist      Target list.
 * \param[in]  element     Element to remove.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListRemoveSlow(vmk_CSList *cslist, vmk_SList_Links *element)
{
   VMK_ASSERT(cslist);
   vmk_SListRemoveSlow(&cslist->slist, element);
   cslist->numElements--;
}

/*
 ***********************************************************************
 * vmk_CSListAppend --                                            */ /**
 *
 * \brief Appends all elements of a list at the end of another.
 *
 * \note The list appended is initialized to an empty list.
 *
 * \param[in]  cslist1     Target list.
 * \param[in]  cslist2     List to append.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListAppend(vmk_CSList *cslist1, vmk_CSList *cslist2)
{
   VMK_ASSERT(cslist1);
   VMK_ASSERT(cslist2);
   vmk_SListAppend(&cslist1->slist, &cslist2->slist);
   cslist1->numElements += cslist2->numElements;
   cslist2->numElements = 0;
}

/*
 ***********************************************************************
 * vmk_CSListAppendN --                                           */ /**
 *
 * \brief Appends N elements of a list at the end of another.
 *
 * \note The list appended is initialized to an empty list.
 *
 * \param[in]  listDest    Target list.
 * \param[in]  listSrc     List to append.
 * \param[in]  num         Number of elements to append.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListAppendN(vmk_CSList *listDest, vmk_CSList *listSrc, vmk_uint32 num)
{
   VMK_ASSERT(listDest);
   VMK_ASSERT(listSrc);
   VMK_ASSERT(listSrc->numElements >= num);
   
   vmk_SListAppendN(&listDest->slist, &listSrc->slist, num);
   listDest->numElements += num;
   listSrc->numElements -= num;
}

/*
 ***********************************************************************
 * vmk_CSListAppend --                                            */ /**
 *
 * \brief Insert all elements of a list at the beginning of another.
 *
 * \note The list prepended is initialized to an empty list.
 *
 * \param[in]  cslist1     Target list.
 * \param[in]  cslist2     List to prepend.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListPrepend(vmk_CSList *cslist1, vmk_CSList *cslist2)
{
   VMK_ASSERT(cslist1);
   VMK_ASSERT(cslist2);
   vmk_SListPrepend(&cslist1->slist, &cslist2->slist);
   cslist1->numElements += cslist2->numElements;
   cslist2->numElements = 0;
}

/*
 ***********************************************************************
 * vmk_CSListSplitNHead --                                        */ /**
 *
 * \brief Split a list into two list starting a given element.
 *
 * \note The second list must be empty.
 *
 * \param[in]  cslist1     Target list, becomes left part of the list.
 * \param[in]  cslist2     Right part of the list.
 * \param[in]  n           Index of the element where to start
 *                         splitting.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListSplitNHead(vmk_CSList *cslist1, vmk_CSList *cslist2, vmk_uint64 n)
{
   vmk_uint32 min;

   VMK_ASSERT(cslist1);
   VMK_ASSERT(cslist2);
   vmk_SListSplitNHead(&cslist1->slist, &cslist2->slist, n);
   min = cslist1->numElements < n ? cslist1->numElements : n;
   cslist2->numElements += min;
   cslist1->numElements -= min;
}

/*
 ***********************************************************************
 * vmk_CSListReplace --                                           */ /**
 *
 * \brief Replace the given entry with a new entry. Runs O(1).
 *
 * \param[in] list         List destination.
 * \param[in] targetEntry  Entry to replace.
 * \param[in] newEntry     New entry.
 * \param[in] prevEntry    Predecessor of the entry to replace.
 *
 ***********************************************************************
 */

static inline void
vmk_CSListReplace(vmk_CSList *list, 
                  vmk_SList_Links *targetEntry,
                  vmk_SList_Links *newEntry, 
                  vmk_SList_Links *prevEntry)
{
   VMK_ASSERT(list);
   VMK_ASSERT(targetEntry);

   vmk_SListReplace(&list->slist, targetEntry, newEntry, prevEntry);
}

#endif
/** @} */
/** @} */