]>
code.delx.au - pulseaudio/blob - src/pulsecore/llist.h
7 This file is part of PulseAudio.
9 Copyright 2004-2006 Lennart Poettering
11 PulseAudio is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 PulseAudio is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with PulseAudio; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <pulsecore/macro.h>
29 /* Some macros for maintaining doubly linked lists */
31 /* The head of the linked list. Use this in the structure that shall
32 * contain the head of the linked list */
33 #define PA_LLIST_HEAD(t,name) \
36 /* The pointers in the linked list's items. Use this in the item structure */
37 #define PA_LLIST_FIELDS(t) \
40 /* Initialize the list's head */
41 #define PA_LLIST_HEAD_INIT(t,item) \
43 (item) = (t*) NULL; } \
46 /* Initialize a list item */
47 #define PA_LLIST_INIT(t,item) \
51 _item->prev = _item->next = NULL; \
54 /* Prepend an item to the list */
55 #define PA_LLIST_PREPEND(t,head,item) \
57 t **_head = &(head), *_item = (item); \
59 if ((_item->next = *_head)) \
60 _item->next->prev = _item; \
65 /* Remove an item from the list */
66 #define PA_LLIST_REMOVE(t,head,item) \
68 t **_head = &(head), *_item = (item); \
71 _item->next->prev = _item->prev; \
73 _item->prev->next = _item->next; \
75 pa_assert(*_head == _item); \
76 *_head = _item->next; \
78 _item->next = _item->prev = NULL; \
81 /* Find the head of the list */
82 #define PA_LLIST_FIND_HEAD(t,item,head) \
84 t **_head = (head), *_item = (item); \
87 while ((*_head)->prev) \
88 *_head = (*_head)->prev; \
91 /* Insert an item after another one (a = where, b = what) */
92 #define PA_LLIST_INSERT_AFTER(t,head,a,b) \
94 t **_head = &(head), *_a = (a), *_b = (b); \
97 if ((_b->next = *_head)) \
98 _b->next->prev = _b; \
102 if ((_b->next = _a->next)) \
103 _b->next->prev = _b; \