patch-output_sqlite3_queue_h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. --- ulogd-2.0.2.orig/output/sqlite3/queue.h 1970-01-01 00:00:00.000000000 +0100
  2. +++ ulogd-2.0.2/output/sqlite3/queue.h 2013-11-11 21:27:31.000000000 +0100
  3. @@ -0,0 +1,574 @@
  4. +/*
  5. + * Copyright (c) 1991, 1993
  6. + * The Regents of the University of California. All rights reserved.
  7. + *
  8. + * Redistribution and use in source and binary forms, with or without
  9. + * modification, are permitted provided that the following conditions
  10. + * are met:
  11. + * 1. Redistributions of source code must retain the above copyright
  12. + * notice, this list of conditions and the following disclaimer.
  13. + * 2. Redistributions in binary form must reproduce the above copyright
  14. + * notice, this list of conditions and the following disclaimer in the
  15. + * documentation and/or other materials provided with the distribution.
  16. + * 3. Neither the name of the University nor the names of its contributors
  17. + * may be used to endorse or promote products derived from this software
  18. + * without specific prior written permission.
  19. + *
  20. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. + * SUCH DAMAGE.
  31. + *
  32. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  33. + */
  34. +
  35. +#ifndef _SYS_QUEUE_H_
  36. +#define _SYS_QUEUE_H_
  37. +
  38. +/*
  39. + * This file defines five types of data structures: singly-linked lists,
  40. + * lists, simple queues, tail queues, and circular queues.
  41. + *
  42. + * A singly-linked list is headed by a single forward pointer. The
  43. + * elements are singly linked for minimum space and pointer manipulation
  44. + * overhead at the expense of O(n) removal for arbitrary elements. New
  45. + * elements can be added to the list after an existing element or at the
  46. + * head of the list. Elements being removed from the head of the list
  47. + * should use the explicit macro for this purpose for optimum
  48. + * efficiency. A singly-linked list may only be traversed in the forward
  49. + * direction. Singly-linked lists are ideal for applications with large
  50. + * datasets and few or no removals or for implementing a LIFO queue.
  51. + *
  52. + * A list is headed by a single forward pointer (or an array of forward
  53. + * pointers for a hash table header). The elements are doubly linked
  54. + * so that an arbitrary element can be removed without a need to
  55. + * traverse the list. New elements can be added to the list before
  56. + * or after an existing element or at the head of the list. A list
  57. + * may only be traversed in the forward direction.
  58. + *
  59. + * A simple queue is headed by a pair of pointers, one the head of the
  60. + * list and the other to the tail of the list. The elements are singly
  61. + * linked to save space, so elements can only be removed from the
  62. + * head of the list. New elements can be added to the list after
  63. + * an existing element, at the head of the list, or at the end of the
  64. + * list. A simple queue may only be traversed in the forward direction.
  65. + *
  66. + * A tail queue is headed by a pair of pointers, one to the head of the
  67. + * list and the other to the tail of the list. The elements are doubly
  68. + * linked so that an arbitrary element can be removed without a need to
  69. + * traverse the list. New elements can be added to the list before or
  70. + * after an existing element, at the head of the list, or at the end of
  71. + * the list. A tail queue may be traversed in either direction.
  72. + *
  73. + * A circle queue is headed by a pair of pointers, one to the head of the
  74. + * list and the other to the tail of the list. The elements are doubly
  75. + * linked so that an arbitrary element can be removed without a need to
  76. + * traverse the list. New elements can be added to the list before or after
  77. + * an existing element, at the head of the list, or at the end of the list.
  78. + * A circle queue may be traversed in either direction, but has a more
  79. + * complex end of list detection.
  80. + *
  81. + * For details on the use of these macros, see the queue(3) manual page.
  82. + */
  83. +
  84. +/*
  85. + * List definitions.
  86. + */
  87. +#define LIST_HEAD(name, type) \
  88. +struct name { \
  89. + struct type *lh_first; /* first element */ \
  90. +}
  91. +
  92. +#define LIST_HEAD_INITIALIZER(head) \
  93. + { NULL }
  94. +
  95. +#define LIST_ENTRY(type) \
  96. +struct { \
  97. + struct type *le_next; /* next element */ \
  98. + struct type **le_prev; /* address of previous next element */ \
  99. +}
  100. +
  101. +/*
  102. + * List functions.
  103. + */
  104. +#define LIST_INIT(head) do { \
  105. + (head)->lh_first = NULL; \
  106. +} while (/*CONSTCOND*/0)
  107. +
  108. +#define LIST_INSERT_AFTER(listelm, elm, field) do { \
  109. + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
  110. + (listelm)->field.le_next->field.le_prev = \
  111. + &(elm)->field.le_next; \
  112. + (listelm)->field.le_next = (elm); \
  113. + (elm)->field.le_prev = &(listelm)->field.le_next; \
  114. +} while (/*CONSTCOND*/0)
  115. +
  116. +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
  117. + (elm)->field.le_prev = (listelm)->field.le_prev; \
  118. + (elm)->field.le_next = (listelm); \
  119. + *(listelm)->field.le_prev = (elm); \
  120. + (listelm)->field.le_prev = &(elm)->field.le_next; \
  121. +} while (/*CONSTCOND*/0)
  122. +
  123. +#define LIST_INSERT_HEAD(head, elm, field) do { \
  124. + if (((elm)->field.le_next = (head)->lh_first) != NULL) \
  125. + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
  126. + (head)->lh_first = (elm); \
  127. + (elm)->field.le_prev = &(head)->lh_first; \
  128. +} while (/*CONSTCOND*/0)
  129. +
  130. +#define LIST_REMOVE(elm, field) do { \
  131. + if ((elm)->field.le_next != NULL) \
  132. + (elm)->field.le_next->field.le_prev = \
  133. + (elm)->field.le_prev; \
  134. + *(elm)->field.le_prev = (elm)->field.le_next; \
  135. +} while (/*CONSTCOND*/0)
  136. +
  137. +#define LIST_FOREACH(var, head, field) \
  138. + for ((var) = ((head)->lh_first); \
  139. + (var); \
  140. + (var) = ((var)->field.le_next))
  141. +
  142. +/*
  143. + * List access methods.
  144. + */
  145. +#define LIST_EMPTY(head) ((head)->lh_first == NULL)
  146. +#define LIST_FIRST(head) ((head)->lh_first)
  147. +#define LIST_NEXT(elm, field) ((elm)->field.le_next)
  148. +
  149. +
  150. +/*
  151. + * Singly-linked List definitions.
  152. + */
  153. +#define SLIST_HEAD(name, type) \
  154. +struct name { \
  155. + struct type *slh_first; /* first element */ \
  156. +}
  157. +
  158. +#define SLIST_HEAD_INITIALIZER(head) \
  159. + { NULL }
  160. +
  161. +#define SLIST_ENTRY(type) \
  162. +struct { \
  163. + struct type *sle_next; /* next element */ \
  164. +}
  165. +
  166. +/*
  167. + * Singly-linked List functions.
  168. + */
  169. +#define SLIST_INIT(head) do { \
  170. + (head)->slh_first = NULL; \
  171. +} while (/*CONSTCOND*/0)
  172. +
  173. +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  174. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  175. + (slistelm)->field.sle_next = (elm); \
  176. +} while (/*CONSTCOND*/0)
  177. +
  178. +#define SLIST_INSERT_HEAD(head, elm, field) do { \
  179. + (elm)->field.sle_next = (head)->slh_first; \
  180. + (head)->slh_first = (elm); \
  181. +} while (/*CONSTCOND*/0)
  182. +
  183. +#define SLIST_REMOVE_HEAD(head, field) do { \
  184. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  185. +} while (/*CONSTCOND*/0)
  186. +
  187. +#define SLIST_REMOVE(head, elm, type, field) do { \
  188. + if ((head)->slh_first == (elm)) { \
  189. + SLIST_REMOVE_HEAD((head), field); \
  190. + } \
  191. + else { \
  192. + struct type *curelm = (head)->slh_first; \
  193. + while(curelm->field.sle_next != (elm)) \
  194. + curelm = curelm->field.sle_next; \
  195. + curelm->field.sle_next = \
  196. + curelm->field.sle_next->field.sle_next; \
  197. + } \
  198. +} while (/*CONSTCOND*/0)
  199. +
  200. +#define SLIST_FOREACH(var, head, field) \
  201. + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
  202. +
  203. +/*
  204. + * Singly-linked List access methods.
  205. + */
  206. +#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
  207. +#define SLIST_FIRST(head) ((head)->slh_first)
  208. +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  209. +
  210. +
  211. +/*
  212. + * Singly-linked Tail queue declarations.
  213. + */
  214. +#define STAILQ_HEAD(name, type) \
  215. +struct name { \
  216. + struct type *stqh_first; /* first element */ \
  217. + struct type **stqh_last; /* addr of last next element */ \
  218. +}
  219. +
  220. +#define STAILQ_HEAD_INITIALIZER(head) \
  221. + { NULL, &(head).stqh_first }
  222. +
  223. +#define STAILQ_ENTRY(type) \
  224. +struct { \
  225. + struct type *stqe_next; /* next element */ \
  226. +}
  227. +
  228. +/*
  229. + * Singly-linked Tail queue functions.
  230. + */
  231. +#define STAILQ_INIT(head) do { \
  232. + (head)->stqh_first = NULL; \
  233. + (head)->stqh_last = &(head)->stqh_first; \
  234. +} while (/*CONSTCOND*/0)
  235. +
  236. +#define STAILQ_INSERT_HEAD(head, elm, field) do { \
  237. + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
  238. + (head)->stqh_last = &(elm)->field.stqe_next; \
  239. + (head)->stqh_first = (elm); \
  240. +} while (/*CONSTCOND*/0)
  241. +
  242. +#define STAILQ_INSERT_TAIL(head, elm, field) do { \
  243. + (elm)->field.stqe_next = NULL; \
  244. + *(head)->stqh_last = (elm); \
  245. + (head)->stqh_last = &(elm)->field.stqe_next; \
  246. +} while (/*CONSTCOND*/0)
  247. +
  248. +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  249. + if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
  250. + (head)->stqh_last = &(elm)->field.stqe_next; \
  251. + (listelm)->field.stqe_next = (elm); \
  252. +} while (/*CONSTCOND*/0)
  253. +
  254. +#define STAILQ_REMOVE_HEAD(head, field) do { \
  255. + if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
  256. + (head)->stqh_last = &(head)->stqh_first; \
  257. +} while (/*CONSTCOND*/0)
  258. +
  259. +#define STAILQ_REMOVE(head, elm, type, field) do { \
  260. + if ((head)->stqh_first == (elm)) { \
  261. + STAILQ_REMOVE_HEAD((head), field); \
  262. + } else { \
  263. + struct type *curelm = (head)->stqh_first; \
  264. + while (curelm->field.stqe_next != (elm)) \
  265. + curelm = curelm->field.stqe_next; \
  266. + if ((curelm->field.stqe_next = \
  267. + curelm->field.stqe_next->field.stqe_next) == NULL) \
  268. + (head)->stqh_last = &(curelm)->field.stqe_next; \
  269. + } \
  270. +} while (/*CONSTCOND*/0)
  271. +
  272. +#define STAILQ_FOREACH(var, head, field) \
  273. + for ((var) = ((head)->stqh_first); \
  274. + (var); \
  275. + (var) = ((var)->field.stqe_next))
  276. +
  277. +#define STAILQ_CONCAT(head1, head2) do { \
  278. + if (!STAILQ_EMPTY((head2))) { \
  279. + *(head1)->stqh_last = (head2)->stqh_first; \
  280. + (head1)->stqh_last = (head2)->stqh_last; \
  281. + STAILQ_INIT((head2)); \
  282. + } \
  283. +} while (/*CONSTCOND*/0)
  284. +
  285. +/*
  286. + * Singly-linked Tail queue access methods.
  287. + */
  288. +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
  289. +#define STAILQ_FIRST(head) ((head)->stqh_first)
  290. +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
  291. +
  292. +
  293. +/*
  294. + * Simple queue definitions.
  295. + */
  296. +#define SIMPLEQ_HEAD(name, type) \
  297. +struct name { \
  298. + struct type *sqh_first; /* first element */ \
  299. + struct type **sqh_last; /* addr of last next element */ \
  300. +}
  301. +
  302. +#define SIMPLEQ_HEAD_INITIALIZER(head) \
  303. + { NULL, &(head).sqh_first }
  304. +
  305. +#define SIMPLEQ_ENTRY(type) \
  306. +struct { \
  307. + struct type *sqe_next; /* next element */ \
  308. +}
  309. +
  310. +/*
  311. + * Simple queue functions.
  312. + */
  313. +#define SIMPLEQ_INIT(head) do { \
  314. + (head)->sqh_first = NULL; \
  315. + (head)->sqh_last = &(head)->sqh_first; \
  316. +} while (/*CONSTCOND*/0)
  317. +
  318. +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  319. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  320. + (head)->sqh_last = &(elm)->field.sqe_next; \
  321. + (head)->sqh_first = (elm); \
  322. +} while (/*CONSTCOND*/0)
  323. +
  324. +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  325. + (elm)->field.sqe_next = NULL; \
  326. + *(head)->sqh_last = (elm); \
  327. + (head)->sqh_last = &(elm)->field.sqe_next; \
  328. +} while (/*CONSTCOND*/0)
  329. +
  330. +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  331. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  332. + (head)->sqh_last = &(elm)->field.sqe_next; \
  333. + (listelm)->field.sqe_next = (elm); \
  334. +} while (/*CONSTCOND*/0)
  335. +
  336. +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
  337. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  338. + (head)->sqh_last = &(head)->sqh_first; \
  339. +} while (/*CONSTCOND*/0)
  340. +
  341. +#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
  342. + if ((head)->sqh_first == (elm)) { \
  343. + SIMPLEQ_REMOVE_HEAD((head), field); \
  344. + } else { \
  345. + struct type *curelm = (head)->sqh_first; \
  346. + while (curelm->field.sqe_next != (elm)) \
  347. + curelm = curelm->field.sqe_next; \
  348. + if ((curelm->field.sqe_next = \
  349. + curelm->field.sqe_next->field.sqe_next) == NULL) \
  350. + (head)->sqh_last = &(curelm)->field.sqe_next; \
  351. + } \
  352. +} while (/*CONSTCOND*/0)
  353. +
  354. +#define SIMPLEQ_FOREACH(var, head, field) \
  355. + for ((var) = ((head)->sqh_first); \
  356. + (var); \
  357. + (var) = ((var)->field.sqe_next))
  358. +
  359. +/*
  360. + * Simple queue access methods.
  361. + */
  362. +#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
  363. +#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
  364. +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  365. +
  366. +
  367. +/*
  368. + * Tail queue definitions.
  369. + */
  370. +#define _TAILQ_HEAD(name, type, qual) \
  371. +struct name { \
  372. + qual type *tqh_first; /* first element */ \
  373. + qual type *qual *tqh_last; /* addr of last next element */ \
  374. +}
  375. +#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
  376. +
  377. +#define TAILQ_HEAD_INITIALIZER(head) \
  378. + { NULL, &(head).tqh_first }
  379. +
  380. +#define _TAILQ_ENTRY(type, qual) \
  381. +struct { \
  382. + qual type *tqe_next; /* next element */ \
  383. + qual type *qual *tqe_prev; /* address of previous next element */\
  384. +}
  385. +#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
  386. +
  387. +/*
  388. + * Tail queue functions.
  389. + */
  390. +#define TAILQ_INIT(head) do { \
  391. + (head)->tqh_first = NULL; \
  392. + (head)->tqh_last = &(head)->tqh_first; \
  393. +} while (/*CONSTCOND*/0)
  394. +
  395. +#define TAILQ_INSERT_HEAD(head, elm, field) do { \
  396. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  397. + (head)->tqh_first->field.tqe_prev = \
  398. + &(elm)->field.tqe_next; \
  399. + else \
  400. + (head)->tqh_last = &(elm)->field.tqe_next; \
  401. + (head)->tqh_first = (elm); \
  402. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  403. +} while (/*CONSTCOND*/0)
  404. +
  405. +#define TAILQ_INSERT_TAIL(head, elm, field) do { \
  406. + (elm)->field.tqe_next = NULL; \
  407. + (elm)->field.tqe_prev = (head)->tqh_last; \
  408. + *(head)->tqh_last = (elm); \
  409. + (head)->tqh_last = &(elm)->field.tqe_next; \
  410. +} while (/*CONSTCOND*/0)
  411. +
  412. +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  413. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  414. + (elm)->field.tqe_next->field.tqe_prev = \
  415. + &(elm)->field.tqe_next; \
  416. + else \
  417. + (head)->tqh_last = &(elm)->field.tqe_next; \
  418. + (listelm)->field.tqe_next = (elm); \
  419. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  420. +} while (/*CONSTCOND*/0)
  421. +
  422. +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  423. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  424. + (elm)->field.tqe_next = (listelm); \
  425. + *(listelm)->field.tqe_prev = (elm); \
  426. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  427. +} while (/*CONSTCOND*/0)
  428. +
  429. +#define TAILQ_REMOVE(head, elm, field) do { \
  430. + if (((elm)->field.tqe_next) != NULL) \
  431. + (elm)->field.tqe_next->field.tqe_prev = \
  432. + (elm)->field.tqe_prev; \
  433. + else \
  434. + (head)->tqh_last = (elm)->field.tqe_prev; \
  435. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  436. +} while (/*CONSTCOND*/0)
  437. +
  438. +#define TAILQ_FOREACH(var, head, field) \
  439. + for ((var) = ((head)->tqh_first); \
  440. + (var); \
  441. + (var) = ((var)->field.tqe_next))
  442. +
  443. +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  444. + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
  445. + (var); \
  446. + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
  447. +
  448. +#define TAILQ_CONCAT(head1, head2, field) do { \
  449. + if (!TAILQ_EMPTY(head2)) { \
  450. + *(head1)->tqh_last = (head2)->tqh_first; \
  451. + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
  452. + (head1)->tqh_last = (head2)->tqh_last; \
  453. + TAILQ_INIT((head2)); \
  454. + } \
  455. +} while (/*CONSTCOND*/0)
  456. +
  457. +/*
  458. + * Tail queue access methods.
  459. + */
  460. +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
  461. +#define TAILQ_FIRST(head) ((head)->tqh_first)
  462. +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  463. +
  464. +#define TAILQ_LAST(head, headname) \
  465. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  466. +#define TAILQ_PREV(elm, headname, field) \
  467. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  468. +
  469. +
  470. +/*
  471. + * Circular queue definitions.
  472. + */
  473. +#define CIRCLEQ_HEAD(name, type) \
  474. +struct name { \
  475. + struct type *cqh_first; /* first element */ \
  476. + struct type *cqh_last; /* last element */ \
  477. +}
  478. +
  479. +#define CIRCLEQ_HEAD_INITIALIZER(head) \
  480. + { (void *)&head, (void *)&head }
  481. +
  482. +#define CIRCLEQ_ENTRY(type) \
  483. +struct { \
  484. + struct type *cqe_next; /* next element */ \
  485. + struct type *cqe_prev; /* previous element */ \
  486. +}
  487. +
  488. +/*
  489. + * Circular queue functions.
  490. + */
  491. +#define CIRCLEQ_INIT(head) do { \
  492. + (head)->cqh_first = (void *)(head); \
  493. + (head)->cqh_last = (void *)(head); \
  494. +} while (/*CONSTCOND*/0)
  495. +
  496. +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  497. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  498. + (elm)->field.cqe_prev = (listelm); \
  499. + if ((listelm)->field.cqe_next == (void *)(head)) \
  500. + (head)->cqh_last = (elm); \
  501. + else \
  502. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  503. + (listelm)->field.cqe_next = (elm); \
  504. +} while (/*CONSTCOND*/0)
  505. +
  506. +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  507. + (elm)->field.cqe_next = (listelm); \
  508. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  509. + if ((listelm)->field.cqe_prev == (void *)(head)) \
  510. + (head)->cqh_first = (elm); \
  511. + else \
  512. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  513. + (listelm)->field.cqe_prev = (elm); \
  514. +} while (/*CONSTCOND*/0)
  515. +
  516. +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  517. + (elm)->field.cqe_next = (head)->cqh_first; \
  518. + (elm)->field.cqe_prev = (void *)(head); \
  519. + if ((head)->cqh_last == (void *)(head)) \
  520. + (head)->cqh_last = (elm); \
  521. + else \
  522. + (head)->cqh_first->field.cqe_prev = (elm); \
  523. + (head)->cqh_first = (elm); \
  524. +} while (/*CONSTCOND*/0)
  525. +
  526. +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  527. + (elm)->field.cqe_next = (void *)(head); \
  528. + (elm)->field.cqe_prev = (head)->cqh_last; \
  529. + if ((head)->cqh_first == (void *)(head)) \
  530. + (head)->cqh_first = (elm); \
  531. + else \
  532. + (head)->cqh_last->field.cqe_next = (elm); \
  533. + (head)->cqh_last = (elm); \
  534. +} while (/*CONSTCOND*/0)
  535. +
  536. +#define CIRCLEQ_REMOVE(head, elm, field) do { \
  537. + if ((elm)->field.cqe_next == (void *)(head)) \
  538. + (head)->cqh_last = (elm)->field.cqe_prev; \
  539. + else \
  540. + (elm)->field.cqe_next->field.cqe_prev = \
  541. + (elm)->field.cqe_prev; \
  542. + if ((elm)->field.cqe_prev == (void *)(head)) \
  543. + (head)->cqh_first = (elm)->field.cqe_next; \
  544. + else \
  545. + (elm)->field.cqe_prev->field.cqe_next = \
  546. + (elm)->field.cqe_next; \
  547. +} while (/*CONSTCOND*/0)
  548. +
  549. +#define CIRCLEQ_FOREACH(var, head, field) \
  550. + for ((var) = ((head)->cqh_first); \
  551. + (var) != (const void *)(head); \
  552. + (var) = ((var)->field.cqe_next))
  553. +
  554. +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  555. + for ((var) = ((head)->cqh_last); \
  556. + (var) != (const void *)(head); \
  557. + (var) = ((var)->field.cqe_prev))
  558. +
  559. +/*
  560. + * Circular queue access methods.
  561. + */
  562. +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
  563. +#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
  564. +#define CIRCLEQ_LAST(head) ((head)->cqh_last)
  565. +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  566. +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  567. +
  568. +#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
  569. + (((elm)->field.cqe_next == (void *)(head)) \
  570. + ? ((head)->cqh_first) \
  571. + : (elm->field.cqe_next))
  572. +#define CIRCLEQ_LOOP_PREV(head, elm, field) \
  573. + (((elm)->field.cqe_prev == (void *)(head)) \
  574. + ? ((head)->cqh_last) \
  575. + : (elm->field.cqe_prev))
  576. +
  577. +#endif /* sys/queue.h */