BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / generic / scsi_periph / dl_list.h
blob36a0d22da90d80fbd547ffa35347b4024990cec4
1 /*
2 ** Copyright 2002/03, Thomas Kurschel. All rights reserved.
3 ** Distributed under the terms of the OpenBeOS License.
4 */
6 /*
7 Macros for double linked lists
8 */
10 #ifndef _DL_LIST_H
11 #define _DL_LIST_H
13 #define REMOVE_DL_LIST( item, head, prefix ) \
14 do { \
15 if( item->prefix##prev ) \
16 item->prefix##prev->prefix##next = item->prefix##next; \
17 else \
18 head = item->prefix##next; \
20 if( item->prefix##next ) \
21 item->prefix##next->prefix##prev = item->prefix##prev; \
22 } while( 0 )
24 #define ADD_DL_LIST_HEAD( item, head, prefix ) \
25 do { \
26 item->prefix##next = head; \
27 item->prefix##prev = NULL; \
29 if( (head) ) \
30 (head)->prefix##prev = item; \
32 (head) = item; \
33 } while( 0 )
35 #define REMOVE_CDL_LIST( item, head, prefix ) \
36 do { \
37 item->prefix##next->prefix##prev = item->prefix##prev; \
38 item->prefix##prev->prefix##next = item->prefix##next; \
40 if( item == (head) ) { \
41 if( item->prefix##next != item ) \
42 (head) = item->prefix##next; \
43 else \
44 (head) = NULL; \
45 } \
46 } while( 0 )
48 #define ADD_CDL_LIST_TAIL( item, type, head, prefix ) \
49 do { \
50 type *old_head = head; \
52 if( old_head ) { \
53 type *first, *last; \
55 first = old_head; \
56 last = first->prefix##prev; \
58 item->prefix##next = first; \
59 item->prefix##prev = last; \
60 first->prefix##prev = item; \
61 last->prefix##next = item; \
62 } else { \
63 head = item; \
64 item->prefix##next = item->prefix##prev = item; \
65 } \
66 } while( 0 )
68 #define ADD_CDL_LIST_HEAD( item, type, head, prefix ) \
69 do { \
70 type *old_head = head; \
72 head = item; \
73 if( old_head ) { \
74 type *first, *last; \
76 first = old_head; \
77 last = first->prefix##prev; \
79 item->prefix##next = first; \
80 item->prefix##prev = last; \
81 first->prefix##prev = item; \
82 last->prefix##next = item; \
83 } else { \
84 item->prefix##next = item->prefix##prev = item; \
85 } \
86 } while( 0 )
88 #endif