1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 **************************************************************************/
30 * List macros heavily inspired by the Linux kernel
31 * list handling. No list looping yet.
33 * Is not threadsafe, so common operations need to
34 * be protected using an external mutex.
37 #ifndef _U_DOUBLE_LIST_H_
38 #define _U_DOUBLE_LIST_H_
46 struct list_head
*prev
;
47 struct list_head
*next
;
51 #define LIST_INITHEAD(__item) \
53 (__item)->prev = (__item); \
54 (__item)->next = (__item); \
57 #define LIST_ADD(__item, __list) \
59 (__item)->prev = (__list); \
60 (__item)->next = (__list)->next; \
61 (__list)->next->prev = (__item); \
62 (__list)->next = (__item); \
65 #define LIST_ADDTAIL(__item, __list) \
67 (__item)->next = (__list); \
68 (__item)->prev = (__list)->prev; \
69 (__list)->prev->next = (__item); \
70 (__list)->prev = (__item); \
73 #define LIST_REPLACE(__from, __to) \
75 (__to)->prev = (__from)->prev; \
76 (__to)->next = (__from)->next; \
77 (__from)->next->prev = (__to); \
78 (__from)->prev->next = (__to); \
81 #define LIST_DEL(__item) \
83 (__item)->prev->next = (__item)->next; \
84 (__item)->next->prev = (__item)->prev; \
87 #define LIST_DELINIT(__item) \
89 (__item)->prev->next = (__item)->next; \
90 (__item)->next->prev = (__item)->prev; \
91 (__item)->next = (__item); \
92 (__item)->prev = (__item); \
95 #define LIST_ENTRY(__type, __item, __field) \
96 ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
98 #define LIST_IS_EMPTY(__list) \
99 ((__list)->next == (__list))
102 #endif /*_U_DOUBLE_LIST_H_*/