Merge branch 'modesetting-gem' of ssh://git.freedesktop.org/git/mesa/drm into modeset...
[profile/ivi/libdrm.git] / libdrm / libdrm_lists.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  * List macros heavily inspired by the Linux kernel
29  * list handling. No list looping yet.
30  */
31
32 typedef struct _drmMMListHead
33 {
34     struct _drmMMListHead *prev;
35     struct _drmMMListHead *next;
36 } drmMMListHead;
37
38 #define DRMINITLISTHEAD(__item)                \
39   do{                                          \
40     (__item)->prev = (__item);                 \
41     (__item)->next = (__item);                 \
42   } while (0)
43
44 #define DRMLISTADD(__item, __list)              \
45   do {                                          \
46     (__item)->prev = (__list);                  \
47     (__item)->next = (__list)->next;            \
48     (__list)->next->prev = (__item);            \
49     (__list)->next = (__item);                  \
50   } while (0)
51
52 #define DRMLISTADDTAIL(__item, __list)          \
53   do {                                          \
54     (__item)->next = (__list);                  \
55     (__item)->prev = (__list)->prev;            \
56     (__list)->prev->next = (__item);            \
57     (__list)->prev = (__item);                  \
58   } while(0)
59
60 #define DRMLISTDEL(__item)                      \
61   do {                                          \
62     (__item)->prev->next = (__item)->next;      \
63     (__item)->next->prev = (__item)->prev;      \
64   } while(0)
65
66 #define DRMLISTDELINIT(__item)                  \
67   do {                                          \
68     (__item)->prev->next = (__item)->next;      \
69     (__item)->next->prev = (__item)->prev;      \
70     (__item)->next = (__item);                  \
71     (__item)->prev = (__item);                  \
72   } while(0)
73
74 #define DRMLISTENTRY(__type, __item, __field)   \
75     ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
76
77 #define DRMLISTEMPTY(__item) ((__item)->next == (__item))
78
79 #define DRMLISTFOREACHSAFE(__item, __temp, __list)                      \
80         for ((__item) = (__list)->next, (__temp) = (__item)->next;      \
81              (__item) != (__list);                                      \
82              (__item) = (__temp), (__temp) = (__item)->next)
83
84 #define DRMLISTFOREACHSAFEREVERSE(__item, __temp, __list)               \
85         for ((__item) = (__list)->prev, (__temp) = (__item)->prev;      \
86              (__item) != (__list);                                      \
87              (__item) = (__temp), (__temp) = (__item)->prev)