]> git.proxmox.com Git - mirror_frr.git/blame - lib/queue.h
bgpd: another change to keep indent.py happy
[mirror_frr.git] / lib / queue.h
CommitLineData
04f7dd64 1/*
cd85bc2e 2 * lists and queues implementations
04f7dd64 3 *
cd85bc2e
JB
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
04f7dd64 8 *
cd85bc2e
JB
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
04f7dd64 13 *
cd85bc2e
JB
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
04f7dd64 17 */
d62a17ae 18
cd85bc2e
JB
19#ifndef _FRR_QUEUE_H
20#define _FRR_QUEUE_H
21
22#if defined(__OpenBSD__) && !defined(STAILQ_HEAD)
23#include "openbsd-queue.h"
24
25/* Try to map FreeBSD implementation to OpenBSD one. */
26#define STAILQ_HEAD(name, type) SIMPLEQ_HEAD(name, type)
27#define STAILQ_HEAD_INITIALIZER(head) SIMPLEQ_HEAD_INITIALIZER(head)
28#define STAILQ_ENTRY(entry) SIMPLEQ_ENTRY(entry)
29
30#define STAILQ_CONCAT(head1, head2) SIMPLEQ_CONCAT(head1, head2)
31#define STAILQ_EMPTY(head) SIMPLEQ_EMPTY(head)
32#define STAILQ_FIRST(head) SIMPLEQ_FIRST(head)
33#define STAILQ_FOREACH(var, head, field) SIMPLEQ_FOREACH(var, head, field)
34#define STAILQ_FOREACH_SAFE(var, head, field, tvar) SIMPLEQ_FOREACH_SAFE(var, head, field, tvar)
35#define STAILQ_INIT(head) SIMPLEQ_INIT(head)
36#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) SIMPLEQ_INSERT_AFTER(head, tqelm, elm, field)
37#define STAILQ_INSERT_HEAD(head, elm, field) SIMPLEQ_INSERT_HEAD(head, elm, field)
38#define STAILQ_INSERT_TAIL(head, elm, field) SIMPLEQ_INSERT_TAIL(head, elm, field)
d62a17ae 39#define STAILQ_LAST(head, type, field) \
cd85bc2e 40 (SIMPLEQ_EMPTY((head)) \
d62a17ae 41 ? NULL \
cd85bc2e
JB
42 : ((struct type *)(void *)((char *)((head)->sqh_last) \
43 - offsetof(struct type, \
d62a17ae 44 field))))
cd85bc2e 45#define STAILQ_NEXT(elm, field) SIMPLEQ_NEXT(elm, field)
d62a17ae 46#define STAILQ_REMOVE(head, elm, type, field) \
47 do { \
cd85bc2e
JB
48 if (SIMPLEQ_FIRST((head)) == (elm)) { \
49 SIMPLEQ_REMOVE_HEAD((head), field); \
d62a17ae 50 } else { \
cd85bc2e
JB
51 struct type *curelm = SIMPLEQ_FIRST((head)); \
52 while (SIMPLEQ_NEXT(curelm, field) != (elm)) \
53 curelm = SIMPLEQ_NEXT(curelm, field); \
54 SIMPLEQ_REMOVE_AFTER(head, curelm, field); \
d62a17ae 55 } \
d62a17ae 56 } while (0)
cd85bc2e
JB
57#define STAILQ_REMOVE_AFTER(head, elm, field) SIMPLEQ_REMOVE_AFTER(head, elm, field)
58#define STAILQ_REMOVE_HEAD(head, field) SIMPLEQ_REMOVE_HEAD(head, field)
d62a17ae 59#define STAILQ_SWAP(head1, head2, type) \
60 do { \
61 struct type *swap_first = STAILQ_FIRST(head1); \
cd85bc2e 62 struct type **swap_last = (head1)->sqh_last; \
d62a17ae 63 STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \
cd85bc2e 64 (head1)->sqh_last = (head2)->sqh_last; \
d62a17ae 65 STAILQ_FIRST(head2) = swap_first; \
cd85bc2e 66 (head2)->sqh_last = swap_last; \
d62a17ae 67 if (STAILQ_EMPTY(head1)) \
cd85bc2e 68 (head1)->sqh_last = &STAILQ_FIRST(head1); \
d62a17ae 69 if (STAILQ_EMPTY(head2)) \
cd85bc2e 70 (head2)->sqh_last = &STAILQ_FIRST(head2); \
d62a17ae 71 } while (0)
04f7dd64 72#else
cd85bc2e
JB
73#include "freebsd-queue.h"
74#endif /* defined(__OpenBSD__) && !defined(STAILQ_HEAD) */
04f7dd64 75
cd85bc2e 76#endif /* _FRR_QUEUE_H */