-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.h
819 lines (744 loc) · 25.8 KB
/
list.h
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
/* SPDX-License-Identifier: MIT */
/* Minimal Linux-like double-linked list helper functions
*
* Copyright (c) 2012-2020, Sven Eckelmann <[email protected]>
*
* License-Filename: LICENSES/preferred/MIT
*/
#ifndef __LINUX_LIKE_LIST_H__
#define __LINUX_LIKE_LIST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#if defined(__GNUC__)
#define LIST_TYPEOF_USE 1
#endif
#if defined(_MSC_VER)
#define __inline__ __inline
#endif
/**
* container_of() - Calculate address of object that contains address ptr
* @ptr: pointer to member variable
* @type: type of the structure containing ptr
* @member: name of the member variable in struct @type
*
* Return: @type pointer of object containing ptr
*/
#ifndef container_of
#ifdef LIST_TYPEOF_USE
#define container_of(ptr, type, member) __extension__ ({ \
const __typeof__(((type *)0)->member) *__pmember = (ptr); \
(type *)((char *)__pmember - offsetof(type, member)); })
#else
#define container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
#endif
#endif
/**
* struct list_head - Head and node of a double-linked list
* @prev: pointer to the previous node in the list
* @next: pointer to the next node in the list
*
* The simple double-linked list consists of a head and nodes attached to
* this head. Both node and head share the same struct type. The list_*
* functions and macros can be used to access and modify this data structure.
*
* The @prev pointer of the list head points to the last list node of the
* list and @next points to the first list node of the list. For an empty list,
* both member variables point to the head.
*
* The list nodes are usually embedded in a container structure which holds the
* actual data. Such an container object is called entry. The helper list_entry
* can be used to calculate the object address from the address of the node.
*/
struct list_head {
struct list_head *prev;
struct list_head *next;
};
/**
* LIST_HEAD - Declare list head and initialize it
* @head: name of the new object
*/
#define LIST_HEAD(head) \
struct list_head head = { &(head), &(head) }
/**
* INIT_LIST_HEAD() - Initialize empty list head
* @head: pointer to list head
*
* This can also be used to initialize a unlinked list node.
*
* A node is usually linked inside a list, will be added to a list in
* the near future or the entry containing the node will be free'd soon.
*
* But an unlinked node may be given to a function which uses list_del(_init)
* before it ends up in a previously mentioned state. The list_del(_init) on an
* initialized node is well defined and safe. But the result of a
* list_del(_init) on an uninitialized node is undefined (unrelated memory is
* modified, crashes, ...).
*/
static __inline__ void INIT_LIST_HEAD(struct list_head *head)
{
head->next = head;
head->prev = head;
}
/**
* list_add() - Add a list node to the beginning of the list
* @node: pointer to the new node
* @head: pointer to the head of the list
*/
static __inline__ void list_add(struct list_head *node,
struct list_head *head)
{
struct list_head *next = head->next;
next->prev = node;
node->next = next;
node->prev = head;
head->next = node;
}
/**
* list_add_tail() - Add a list node to the end of the list
* @node: pointer to the new node
* @head: pointer to the head of the list
*/
static __inline__ void list_add_tail(struct list_head *node,
struct list_head *head)
{
struct list_head *prev = head->prev;
prev->next = node;
node->next = head;
node->prev = prev;
head->prev = node;
}
/**
* list_add_before() - Add a list node before another node to the list
* @new_node: pointer to the new node
* @node: pointer to the reference node in the list
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define list_add_before(new_node, node) \
list_add_tail(new_node, node)
/**
* list_add_behind() - Add a list node behind another node to the list
* @new_node: pointer to the new node
* @node: pointer to the reference node in the list
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define list_add_behind(new_node, node) \
list_add(new_node, node)
/**
* list_del() - Remove a list node from the list
* @node: pointer to the node
*
* The node is only removed from the list. Neither the memory of the removed
* node nor the memory of the entry containing the node is free'd. The node
* has to be handled like an uninitialized node. Accessing the next or prev
* pointer of the node is not safe.
*
* Unlinked, initialized nodes are also uninitialized after list_del.
*
* LIST_POISONING can be enabled during build-time to provoke an invalid memory
* access when the memory behind the next/prev pointer is used after a list_del.
* This only works on systems which prohibit access to the predefined memory
* addresses.
*/
static __inline__ void list_del(struct list_head *node)
{
struct list_head *next = node->next;
struct list_head *prev = node->prev;
next->prev = prev;
prev->next = next;
#ifdef LIST_POISONING
node->prev = (struct list_head *)(0x00100100);
node->next = (struct list_head *)(0x00200200);
#endif
}
/**
* list_del_init() - Remove a list node from the list and reinitialize it
* @node: pointer to the node
*
* The removed node will not end up in an uninitialized state like when using
* list_del. Instead the node is initialized again to the unlinked state.
*/
static __inline__ void list_del_init(struct list_head *node)
{
list_del(node);
INIT_LIST_HEAD(node);
}
/**
* list_empty() - Check if list head has no nodes attached
* @head: pointer to the head of the list
*
* Return: 0 - list is not empty !0 - list is empty
*/
static __inline__ int list_empty(const struct list_head *head)
{
return (head->next == head);
}
/**
* list_is_singular() - Check if list head has exactly one node attached
* @head: pointer to the head of the list
*
* Return: 0 - list is not singular !0 -list has exactly one entry
*/
static __inline__ int list_is_singular(const struct list_head *head)
{
return (!list_empty(head) && head->prev == head->next);
}
/**
* list_splice() - Add list nodes from a list to beginning of another list
* @list: pointer to the head of the list with the node entries
* @head: pointer to the head of the list
*
* All nodes from @list are added to to the beginning of the list of @head.
* It is similar to list_add but for multiple nodes. The @list head is not
* modified and has to be initialized to be used as a valid list head/node
* again.
*/
static __inline__ void list_splice(struct list_head *list,
struct list_head *head)
{
struct list_head *head_first = head->next;
struct list_head *list_first = list->next;
struct list_head *list_last = list->prev;
if (list_empty(list))
return;
head->next = list_first;
list_first->prev = head;
list_last->next = head_first;
head_first->prev = list_last;
}
/**
* list_splice_tail() - Add list nodes from a list to end of another list
* @list: pointer to the head of the list with the node entries
* @head: pointer to the head of the list
*
* All nodes from @list are added to to the end of the list of @head.
* It is similar to list_add_tail but for multiple nodes. The @list head is not
* modified and has to be initialized to be used as a valid list head/node
* again.
*/
static __inline__ void list_splice_tail(struct list_head *list,
struct list_head *head)
{
struct list_head *head_last = head->prev;
struct list_head *list_first = list->next;
struct list_head *list_last = list->prev;
if (list_empty(list))
return;
head->prev = list_last;
list_last->next = head;
list_first->prev = head_last;
head_last->next = list_first;
}
/**
* list_splice_init() - Move list nodes from a list to beginning of another list
* @list: pointer to the head of the list with the node entries
* @head: pointer to the head of the list
*
* All nodes from @list are added to to the beginning of the list of @head.
* It is similar to list_add but for multiple nodes.
*
* The @list head will not end up in an uninitialized state like when using
* list_splice. Instead the @list is initialized again to the an empty
* list/unlinked state.
*/
static __inline__ void list_splice_init(struct list_head *list,
struct list_head *head)
{
list_splice(list, head);
INIT_LIST_HEAD(list);
}
/**
* list_splice_tail_init() - Move list nodes from a list to end of another list
* @list: pointer to the head of the list with the node entries
* @head: pointer to the head of the list
*
* All nodes from @list are added to to the end of the list of @head.
* It is similar to list_add_tail but for multiple nodes.
*
* The @list head will not end up in an uninitialized state like when using
* list_splice. Instead the @list is initialized again to the an empty
* list/unlinked state.
*/
static __inline__ void list_splice_tail_init(struct list_head *list,
struct list_head *head)
{
list_splice_tail(list, head);
INIT_LIST_HEAD(list);
}
/**
* list_cut_position() - Move beginning of a list to another list
* @head_to: pointer to the head of the list which receives nodes
* @head_from: pointer to the head of the list
* @node: pointer to the node in which defines the cutting point
*
* All entries from the beginning of the list @head_from to (including) the
* @node is moved to @head_from.
*
* @head_to is replaced when @head_from is not empty. @node must be a real
* list node from @head_from or the behavior is undefined.
*/
static __inline__ void list_cut_position(struct list_head *head_to,
struct list_head *head_from,
struct list_head *node)
{
struct list_head *head_from_first = head_from->next;
if (list_empty(head_from))
return;
if (head_from == node) {
INIT_LIST_HEAD(head_to);
return;
}
head_from->next = node->next;
head_from->next->prev = head_from;
head_to->prev = node;
node->next = head_to;
head_to->next = head_from_first;
head_to->next->prev = head_to;
}
/**
* list_move() - Move a list node to the beginning of the list
* @node: pointer to the node
* @head: pointer to the head of the list
*
* The @node is removed from its old position/node and add to the beginning of
* @head
*/
static __inline__ void list_move(struct list_head *node, struct list_head *head)
{
list_del(node);
list_add(node, head);
}
/**
* list_move_tail() - Move a list node to the end of the list
* @node: pointer to the node
* @head: pointer to the head of the list
*
* The @node is removed from its old position/node and add to the end of @head
*/
static __inline__ void list_move_tail(struct list_head *node,
struct list_head *head)
{
list_del(node);
list_add_tail(node, head);
}
/**
* list_entry() - Calculate address of entry that contains list node
* @node: pointer to list node
* @type: type of the entry containing the list node
* @member: name of the list_head member variable in struct @type
*
* Return: @type pointer of entry containing node
*/
#define list_entry(node, type, member) container_of(node, type, member)
/**
* list_first_entry() - get first entry of the list
* @head: pointer to the head of the list
* @type: type of the entry containing the list node
* @member: name of the list_head member variable in struct @type
*
* Return: @type pointer of first entry in list
*/
#define list_first_entry(head, type, member) \
list_entry((head)->next, type, member)
/**
* list_last_entry() - get last entry of the list
* @head: pointer to the head of the list
* @type: type of the entry containing the list node
* @member: name of the list_head member variable in struct @type
*
* Return: @type pointer of last entry in list
*/
#define list_last_entry(head, type, member) \
list_entry((head)->prev, type, member)
/**
* list_for_each - iterate over list nodes
* @node: list_head pointer used as iterator
* @head: pointer to the head of the list
*
* The nodes and the head of the list must must be kept unmodified while
* iterating through it. Any modifications to the the list will cause undefined
* behavior.
*/
#define list_for_each(node, head) \
for (node = (head)->next; \
node != (head); \
node = node->next)
/**
* list_for_each_entry_t - iterate over list entries
* @entry: @type pointer used as iterator
* @head: pointer to the head of the list
* @type: type of the entries containing the list nodes
* @member: name of the list_head member variable in struct @type
*
* The nodes and the head of the list must must be kept unmodified while
* iterating through it. Any modifications to the the list will cause undefined
* behavior.
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define list_for_each_entry_t(entry, head, type, member) \
for (entry = list_entry((head)->next, type, member); \
&entry->member != (head); \
entry = list_entry(entry->member.next, type, member))
/**
* list_for_each_entry - iterate over list entries
* @entry: pointer used as iterator
* @head: pointer to the head of the list
* @member: name of the list_head member variable in struct type of @entry
*
* The nodes and the head of the list must must be kept unmodified while
* iterating through it. Any modifications to the the list will cause undefined
* behavior.
*/
#ifdef LIST_TYPEOF_USE
#define list_for_each_entry(entry, head, member) \
list_for_each_entry_t(entry, head, __typeof__(*entry), member)
#endif
/**
* list_for_each_safe - iterate over list nodes and allow deletes
* @node: list_head pointer used as iterator
* @safe: list_head pointer used to store info for next entry in list
* @head: pointer to the head of the list
*
* The current node (iterator) is allowed to be removed from the list. Any
* other modifications to the the list will cause undefined behavior.
*/
#define list_for_each_safe(node, safe, head) \
for (node = (head)->next, safe = node->next; \
node != (head); \
node = safe, safe = node->next)
/**
* list_for_each_entry_safe_t - iterate over list entries and allow deletes
* @entry: @type pointer used as iterator
* @safe: @type pointer used to store info for next entry in list
* @head: pointer to the head of the list
* @type: type of the entries containing the list nodes
* @member: name of the list_head member variable in struct @type
*
* The current node (iterator) is allowed to be removed from the list. Any
* other modifications to the the list will cause undefined behavior.
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define list_for_each_entry_safe_t(entry, safe, head, type, member) \
for (entry = list_entry((head)->next, type, member), \
safe = list_entry(entry->member.next, type, member); \
&entry->member != (head); \
entry = safe, \
safe = list_entry(safe->member.next, type, member))
/**
* list_for_each_entry_safe - iterate over list entries and allow deletes
* @entry: pointer used as iterator
* @safe: @type pointer used to store info for next entry in list
* @head: pointer to the head of the list
* @member: name of the list_head member variable in struct type of @entry
*
* The current node (iterator) is allowed to be removed from the list. Any
* other modifications to the the list will cause undefined behavior.
*/
#ifdef LIST_TYPEOF_USE
#define list_for_each_entry_safe(entry, safe, head, member) \
list_for_each_entry_safe_t(entry, safe, head, __typeof__(*entry), \
member)
#endif
/**
* struct hlist_node - Node of a double-linked list with single pointer head
* @next: pointer to the next node in the list
* @pprev: pointer to @next of the previous node in the hlist
*
* The double-linked list with single pointer head consists of a head and nodes
* attached to this head. The hlist_* functions and macros can be used to access
* and modify this data structure.
*
* The @pprev pointer is used to find the previous node (or head) in the list
* when doing hlist_del operations
*
* The hlist nodes are usually embedded in a container structure which holds the
* actual data. Such an container object is called entry. The helper hlist_entry
* can be used to calculate the object address from the address of the node.
*/
struct hlist_node {
struct hlist_node *next;
struct hlist_node **pprev;
};
/**
* struct hlist_head - Head of a double-linked list with single pointer head
* @first: pointer to the first node in the hlist
*
* The hlist doesn't have a pointer to the last node. This makes it harder to
* access or modify the tail of the list. But the single pointer to the first
* entry makes it well suited for implementation of hash tables because it
* cuts the size cost of the head pointers by half compared to the list_head.
*/
struct hlist_head {
struct hlist_node *first;
};
/**
* HLIST_HEAD - Declare hlist head and initialize it
* @head: name of the new object
*/
#define HLIST_HEAD(head) \
struct hlist_head head = { NULL }
/**
* INIT_HLIST_HEAD() - Initialize empty hlist head
* @head: pointer to hlist head
*/
static __inline__ void INIT_HLIST_HEAD(struct hlist_head *head)
{
head->first = NULL;
}
/**
* INIT_HLIST_NODE() - Initialize unhashed hlist node
* @node: pointer to hlist node
*
* A hlist_node is usually linked inside a hlist, will be added to a hlist in
* the near future or the entry containing the node will be free'd soon.
*
* But an unlinked node may be given to a function which uses hlist_del(_init)
* before it ends up in a previously mentioned state. The hlist_del(_init) on an
* initialized node is well defined and safe. But the result of a
* hlist_del(_init) on an uninitialized node is undefined (unrelated memory is
* modified, crashes, ...).
*/
static __inline__ void INIT_HLIST_NODE(struct hlist_node *node)
{
node->next = NULL;
node->pprev = NULL;
}
/**
* hlist_add_head() - Add a hlist node to the beginning of the hlist
* @node: pointer to the new node
* @head: pointer to the head of the hlist
*/
static __inline__ void hlist_add_head(struct hlist_node *node,
struct hlist_head *head)
{
struct hlist_node *first = head->first;
head->first = node;
node->next = first;
node->pprev = &head->first;
if (first)
first->pprev = &node->next;
}
/**
* hlist_add_before() - Add a hlist node before another node to the hlist
* @new_node: pointer to the new node
* @node: pointer to the reference node in the hlist
*/
static __inline__ void hlist_add_before(struct hlist_node *new_node,
struct hlist_node *node)
{
struct hlist_node **pprev = node->pprev;
*pprev = new_node;
new_node->next = node;
new_node->pprev = pprev;
node->pprev = &new_node->next;
}
/**
* hlist_add_behind() - Add a hlist node behind another node to the hlist
* @new_node: pointer to the new node
* @node: pointer to the reference node in the hlist
*/
static __inline__ void hlist_add_behind(struct hlist_node *new_node,
struct hlist_node *node)
{
struct hlist_node *next = node->next;
node->next = new_node;
new_node->pprev = &node->next;
new_node->next = next;
if (next)
next->pprev = &new_node->next;
}
/**
* hlist_del() - Remove a hlist node from the hlist
* @node: pointer to the node
*
* The node is only removed from the hlist. Neither the memory of the removed
* node nor the memory of the entry containing the node is free'd. The node
* has to be handled like an uninitialized node. Accessing the next or pprev
* pointer of the node is not safe.
*
* Unlinked, initialized nodes are also uninitialized after hlist_del.
*
* LIST_POISONING can be enabled during build-time to provoke an invalid memory
* access when the memory behind the next/prev pointer is used after an
* hlist_del. This only works on systems which prohibit access to the predefined
* memory addresses.
*/
static __inline__ void hlist_del(struct hlist_node *node)
{
struct hlist_node *next = node->next;
struct hlist_node **pprev = node->pprev;
if (pprev)
*pprev = next;
if (next)
next->pprev = pprev;
#ifdef LIST_POISONING
node->pprev = (struct hlist_node **)(0x00100100);
node->next = (struct hlist_node *)(0x00200200);
#endif
}
/**
* hlist_del_init() - Remove a hlist node from the hlist and reinitialize it
* @node: pointer to the node
*
* The removed node will not end up in an uninitialized state like when using
* hlist_del. Instead the node is initialized again to the unlinked state.
*/
static __inline__ void hlist_del_init(struct hlist_node *node)
{
hlist_del(node);
INIT_HLIST_NODE(node);
}
/**
* hlist_empty() - Check if hlist head has no nodes attached
* @head: pointer to the head of the hlist
*
* Return: 0 - hlist is not empty !0 - hlist is empty
*/
static __inline__ int hlist_empty(const struct hlist_head *head)
{
return !head->first;
}
/**
* hlist_move_list() - Move hlist nodes from a hlist head new hlist head
* @list: pointer to the head of the hlist with the node entries
* @head: pointer to the head of the hlist
*
* All nodes from @list are added to to the beginning of the list of @head.
* @head can be uninitialized or an empty, initialized hlist. All entries of
* a non-empty hlist @head would be lost after this operation.
*
* The @list head will not end up in an uninitialized state. Instead the @list
* is initialized again to an empty hlist.
*/
static __inline__ void hlist_move_list(struct hlist_head *list,
struct hlist_head *head)
{
head->first = list->first;
if (head->first)
head->first->pprev = &head->first;
INIT_HLIST_HEAD(list);
}
/**
* hlist_entry() - Calculate address of entry that contains hlist node
* @node: pointer to hlist node
* @type: type of the entry containing the hlist node
* @member: name of the hlist_node member variable in struct @type
*
* Return: @type pointer of entry containing node
*/
#define hlist_entry(node, type, member) container_of(node, type, member)
/**
* hlist_entry_safe() - Calculate address of entry that contains hlist node
* @node: pointer to hlist node or (struct hlist_node *)NULL
* @type: type of the entry containing the hlist node
* @member: name of the hlist_node member variable in struct @type
*
* Return: @type pointer of entry containing node or NULL
*/
#ifdef LIST_TYPEOF_USE
#define hlist_entry_safe(node, type, member) __extension__ ({ \
__typeof__(node) __node = (node); \
!__node ? NULL : hlist_entry(__node, type, member); })
#else
#define hlist_entry_safe(node, type, member) \
(node) ? hlist_entry(node, type, member) : NULL
#endif
/**
* hlist_for_each - iterate over hlist nodes
* @node: hlist_node pointer used as iterator
* @head: pointer to the head of the hlist
*
* The nodes and the head of the hlist must must be kept unmodified while
* iterating through it. Any modifications to the the hlist will cause undefined
* behavior.
*/
#define hlist_for_each(node, head) \
for (node = (head)->first; \
node; \
node = node->next)
/**
* hlist_for_each_entry_t - iterate over hlist entries
* @entry: @type pointer used as iterator
* @head: pointer to the head of the hlist
* @type: type of the entries containing the hlist nodes
* @member: name of the hlist_node member variable in struct @type
*
* The nodes and the head of the hlist must must be kept unmodified while
* iterating through it. Any modifications to the the hlist will cause undefined
* behavior.
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define hlist_for_each_entry_t(entry, head, type, member) \
for (entry = hlist_entry_safe((head)->first, type, member); \
entry; \
entry = hlist_entry_safe(entry->member.next, type, member))
/**
* hlist_for_each_entry - iterate over hlist entries
* @entry: pointer used as iterator
* @head: pointer to the head of the hlist
* @member: name of the hlist_node member variable in struct type of @entry
*
* The nodes and the head of the hlist must must be kept unmodified while
* iterating through it. Any modifications to the the hlist will cause undefined
* behavior.
*/
#ifdef LIST_TYPEOF_USE
#define hlist_for_each_entry(entry, head, member) \
hlist_for_each_entry_t(entry, head, __typeof__(*entry), member)
#endif
/**
* hlist_for_each_safe - iterate over hlist nodes and allow deletes
* @node: hlist_node pointer used as iterator
* @safe: hlist_node pointer used to store info for next entry in hlist
* @head: pointer to the head of the hlist
*
* The current node (iterator) is allowed to be removed from the hlist. Any
* other modifications to the the hlist will cause undefined behavior.
*/
#define hlist_for_each_safe(node, safe, head) \
for (node = (head)->first; \
node && ((safe = node->next) || 1); \
node = safe)
/**
* hlist_for_each_entry_safe_t - iterate over hlist entries and allow deletes
* @entry: @type pointer used as iterator
* @safe: hlist_node pointer used to store info for next entry in hlist
* @head: pointer to the head of the hlist
* @type: type of the entries containing the hlist nodes
* @member: name of the hlist_node member variable in struct @type
*
* The current node (iterator) is allowed to be removed from the hlist. Any
* other modifications to the the hlist will cause undefined behavior.
*
* WARNING this functionality is not available in the Linux list implementation
*/
#define hlist_for_each_entry_safe_t(entry, safe, head, type, member) \
for (entry = hlist_entry_safe((head)->first, type, member); \
entry && ((safe = entry->member.next) || 1); \
entry = hlist_entry_safe(safe, type, member))
/**
* hlist_for_each_entry_safe - iterate over hlist entries and allow deletes
* @entry: pointer used as iterator
* @safe: hlist_node pointer used to store info for next entry in hlist
* @head: pointer to the head of the hlist
* @member: name of the hlist_node member variable in struct type of @entry
*
* The current node (iterator) is allowed to be removed from the hlist. Any
* other modifications to the the hlist will cause undefined behavior.
*/
#ifdef LIST_TYPEOF_USE
#define hlist_for_each_entry_safe(entry, safe, head, member) \
hlist_for_each_entry_safe_t(entry, safe, head, __typeof__(*entry),\
member)
#endif
#ifdef __cplusplus
}
#endif
#endif /* __LINUX_LIKE_LIST_H__ */