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: #ifndef _SYS_QUEUE_H
33: #define _SYS_QUEUE_H 1
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: #define LIST_HEAD(name, type) \
68: struct name { \
69: struct type *lh_first; \
70: }
71:
72: #define LIST_ENTRY(type) \
73: struct { \
74: struct type *le_next; \
75: struct type **le_prev; \
76: }
77:
78:
79:
80:
81: #define LIST_INIT(head) { \
82: (head)->lh_first = NULL; \
83: }
84:
85: #define LIST_INSERT_AFTER(listelm, elm, field) { \
86: if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
87: (listelm)->field.le_next->field.le_prev = \
88: &(elm)->field.le_next; \
89: (listelm)->field.le_next = (elm); \
90: (elm)->field.le_prev = &(listelm)->field.le_next; \
91: }
92:
93: #define LIST_INSERT_HEAD(head, elm, field) { \
94: if (((elm)->field.le_next = (head)->lh_first) != NULL) \
95: (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
96: (head)->lh_first = (elm); \
97: (elm)->field.le_prev = &(head)->lh_first; \
98: }
99:
100: #define LIST_REMOVE(elm, field) { \
101: if ((elm)->field.le_next != NULL) \
102: (elm)->field.le_next->field.le_prev = \
103: (elm)->field.le_prev; \
104: *(elm)->field.le_prev = (elm)->field.le_next; \
105: }
106:
107:
108:
109:
110: #define TAILQ_HEAD(name, type) \
111: struct name { \
112: struct type *tqh_first; \
113: struct type **tqh_last; \
114: }
115:
116: #define TAILQ_ENTRY(type) \
117: struct { \
118: struct type *tqe_next; \
119: struct type **tqe_prev; \
120: }
121:
122:
123:
124:
125: #define TAILQ_INIT(head) { \
126: (head)->tqh_first = NULL; \
127: (head)->tqh_last = &(head)->tqh_first; \
128: }
129:
130: #define TAILQ_INSERT_HEAD(head, elm, field) { \
131: if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
132: (elm)->field.tqe_next->field.tqe_prev = \
133: &(elm)->field.tqe_next; \
134: else \
135: (head)->tqh_last = &(elm)->field.tqe_next; \
136: (head)->tqh_first = (elm); \
137: (elm)->field.tqe_prev = &(head)->tqh_first; \
138: }
139:
140: #define TAILQ_INSERT_TAIL(head, elm, field) { \
141: (elm)->field.tqe_next = NULL; \
142: (elm)->field.tqe_prev = (head)->tqh_last; \
143: *(head)->tqh_last = (elm); \
144: (head)->tqh_last = &(elm)->field.tqe_next; \
145: }
146:
147: #define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \
148: if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
149: (elm)->field.tqe_next->field.tqe_prev = \
150: &(elm)->field.tqe_next; \
151: else \
152: (head)->tqh_last = &(elm)->field.tqe_next; \
153: (listelm)->field.tqe_next = (elm); \
154: (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
155: }
156:
157: #define TAILQ_REMOVE(head, elm, field) { \
158: if (((elm)->field.tqe_next) != NULL) \
159: (elm)->field.tqe_next->field.tqe_prev = \
160: (elm)->field.tqe_prev; \
161: else \
162: (head)->tqh_last = (elm)->field.tqe_prev; \
163: *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
164: }
165:
166:
167:
168:
169: #define CIRCLEQ_HEAD(name, type) \
170: struct name { \
171: struct type *cqh_first; \
172: struct type *cqh_last; \
173: }
174:
175: #define CIRCLEQ_ENTRY(type) \
176: struct { \
177: struct type *cqe_next; \
178: struct type *cqe_prev; \
179: }
180:
181:
182:
183:
184: #define CIRCLEQ_INIT(head) { \
185: (head)->cqh_first = (void *)(head); \
186: (head)->cqh_last = (void *)(head); \
187: }
188:
189: #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
190: (elm)->field.cqe_next = (listelm)->field.cqe_next; \
191: (elm)->field.cqe_prev = (listelm); \
192: if ((listelm)->field.cqe_next == (void *)(head)) \
193: (head)->cqh_last = (elm); \
194: else \
195: (listelm)->field.cqe_next->field.cqe_prev = (elm); \
196: (listelm)->field.cqe_next = (elm); \
197: }
198:
199: #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
200: (elm)->field.cqe_next = (listelm); \
201: (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
202: if ((listelm)->field.cqe_prev == (void *)(head)) \
203: (head)->cqh_first = (elm); \
204: else \
205: (listelm)->field.cqe_prev->field.cqe_next = (elm); \
206: (listelm)->field.cqe_prev = (elm); \
207: }
208:
209: #define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
210: (elm)->field.cqe_next = (head)->cqh_first; \
211: (elm)->field.cqe_prev = (void *)(head); \
212: if ((head)->cqh_last == (void *)(head)) \
213: (head)->cqh_last = (elm); \
214: else \
215: (head)->cqh_first->field.cqe_prev = (elm); \
216: (head)->cqh_first = (elm); \
217: }
218:
219: #define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
220: (elm)->field.cqe_next = (void *)(head); \
221: (elm)->field.cqe_prev = (head)->cqh_last; \
222: if ((head)->cqh_first == (void *)(head)) \
223: (head)->cqh_first = (elm); \
224: else \
225: (head)->cqh_last->field.cqe_next = (elm); \
226: (head)->cqh_last = (elm); \
227: }
228:
229: #define CIRCLEQ_REMOVE(head, elm, field) { \
230: if ((elm)->field.cqe_next == (void *)(head)) \
231: (head)->cqh_last = (elm)->field.cqe_prev; \
232: else \
233: (elm)->field.cqe_next->field.cqe_prev = \
234: (elm)->field.cqe_prev; \
235: if ((elm)->field.cqe_prev == (void *)(head)) \
236: (head)->cqh_first = (elm)->field.cqe_next; \
237: else \
238: (elm)->field.cqe_prev->field.cqe_next = \
239: (elm)->field.cqe_next; \
240: }
241: #endif