Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / auxiliary / util / u_double_list.h
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
4 * All Rights Reserved.
5 *
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:
13 *
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.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28 /**
29 * \file
30 * List macros heavily inspired by the Linux kernel
31 * list handling. No list looping yet.
32 *
33 * Is not threadsafe, so common operations need to
34 * be protected using an external mutex.
35 */
36
37 #ifndef _U_DOUBLE_LIST_H_
38 #define _U_DOUBLE_LIST_H_
39
40
41 #include <stddef.h>
42
43
44 struct list_head
45 {
46 struct list_head *prev;
47 struct list_head *next;
48 };
49
50
51 #define LIST_INITHEAD(__item) \
52 do { \
53 (__item)->prev = (__item); \
54 (__item)->next = (__item); \
55 } while (0)
56
57 #define LIST_ADD(__item, __list) \
58 do { \
59 (__item)->prev = (__list); \
60 (__item)->next = (__list)->next; \
61 (__list)->next->prev = (__item); \
62 (__list)->next = (__item); \
63 } while (0)
64
65 #define LIST_ADDTAIL(__item, __list) \
66 do { \
67 (__item)->next = (__list); \
68 (__item)->prev = (__list)->prev; \
69 (__list)->prev->next = (__item); \
70 (__list)->prev = (__item); \
71 } while(0)
72
73 #define LIST_REPLACE(__from, __to) \
74 do { \
75 (__to)->prev = (__from)->prev; \
76 (__to)->next = (__from)->next; \
77 (__from)->next->prev = (__to); \
78 (__from)->prev->next = (__to); \
79 } while (0)
80
81 #define LIST_DEL(__item) \
82 do { \
83 (__item)->prev->next = (__item)->next; \
84 (__item)->next->prev = (__item)->prev; \
85 } while(0)
86
87 #define LIST_DELINIT(__item) \
88 do { \
89 (__item)->prev->next = (__item)->next; \
90 (__item)->next->prev = (__item)->prev; \
91 (__item)->next = (__item); \
92 (__item)->prev = (__item); \
93 } while(0)
94
95 #define LIST_ENTRY(__type, __item, __field) \
96 ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
97
98 #define LIST_IS_EMPTY(__list) \
99 ((__list)->next == (__list))
100
101
102 #endif /*_U_DOUBLE_LIST_H_*/