5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include <pulsecore/macro.h>
27 /* Some macros for maintaining doubly linked lists */
29 /* The head of the linked list. Use this in the structure that shall
30 * contain the head of the linked list */
31 #define PA_LLIST_HEAD(t,name) \
34 /* The pointers in the linked list's items. Use this in the item structure */
35 #define PA_LLIST_FIELDS(t) \
38 /* Initialize the list's head */
39 #define PA_LLIST_HEAD_INIT(t,item) \
41 (item) = (t*) NULL; } \
44 /* Initialize a list item */
45 #define PA_LLIST_INIT(t,item) \
49 _item->prev = _item->next = NULL; \
52 /* Prepend an item to the list */
53 #define PA_LLIST_PREPEND(t,head,item) \
55 t **_head = &(head), *_item = (item); \
57 if ((_item->next = *_head)) \
58 _item->next->prev = _item; \
63 /* Remove an item from the list */
64 #define PA_LLIST_REMOVE(t,head,item) \
66 t **_head = &(head), *_item = (item); \
69 _item->next->prev = _item->prev; \
71 _item->prev->next = _item->next; \
73 pa_assert(*_head == _item); \
74 *_head = _item->next; \
76 _item->next = _item->prev = NULL; \
79 /* Find the head of the list */
80 #define PA_LLIST_FIND_HEAD(t,item,head) \
82 t **_head = (head), *_item = (item); \
85 while ((*_head)->prev) \
86 *_head = (*_head)->prev; \
89 /* Insert an item after another one (a = where, b = what) */
90 #define PA_LLIST_INSERT_AFTER(t,head,a,b) \
92 t **_head = &(head), *_a = (a), *_b = (b); \
95 if ((_b->next = *_head)) \
96 _b->next->prev = _b; \
100 if ((_b->next = _a->next)) \
101 _b->next->prev = _b; \
107 #define PA_LLIST_FOREACH(i,head) \
108 for (i = (head); i; i = i->next)
110 #define PA_LLIST_FOREACH_SAFE(i,n,head) \
111 for (i = (head); i && ((n = i->next), 1); i = n)