aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Skeggs2011-12-17 07:37:20 -0600
committerBen Skeggs2012-04-13 11:47:04 -0500
commit0d6350002d74848dd3d1e4d28d514a7ac9d580c9 (patch)
tree7160d9cb68222a1ede9b8854c351d203354440b6 /libdrm_lists.h
parentf00efc7ab442f106d3ac7699e80f1f7aee8451f4 (diff)
downloadexternal-libdrm-0d6350002d74848dd3d1e4d28d514a7ac9d580c9.tar.gz
external-libdrm-0d6350002d74848dd3d1e4d28d514a7ac9d580c9.tar.xz
external-libdrm-0d6350002d74848dd3d1e4d28d514a7ac9d580c9.zip
lists: add nicer+unsafe foreach, and list join macros
Signed-off-by: Ben Skeggs <bskeggs@redhat.com> Signed-off-by: Christoph Bumiller <e0425955@student.tuwien.ac.at>
Diffstat (limited to 'libdrm_lists.h')
-rw-r--r--libdrm_lists.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/libdrm_lists.h b/libdrm_lists.h
index 6410f573..8926d8d1 100644
--- a/libdrm_lists.h
+++ b/libdrm_lists.h
@@ -78,6 +78,13 @@ typedef struct _drmMMListHead
78 78
79#define DRMLISTEMPTY(__item) ((__item)->next == (__item)) 79#define DRMLISTEMPTY(__item) ((__item)->next == (__item))
80 80
81#define DRMLISTSINGLE(__list) \
82 (!DRMLISTEMPTY(__list) && ((__list)->next == (__list)->prev))
83
84#define DRMLISTFOREACH(__item, __list) \
85 for ((__item) = (__list)->next; \
86 (__item) != (__list); (__item) = (__item)->next)
87
81#define DRMLISTFOREACHSAFE(__item, __temp, __list) \ 88#define DRMLISTFOREACHSAFE(__item, __temp, __list) \
82 for ((__item) = (__list)->next, (__temp) = (__item)->next; \ 89 for ((__item) = (__list)->next, (__temp) = (__item)->next; \
83 (__item) != (__list); \ 90 (__item) != (__list); \
@@ -87,3 +94,25 @@ typedef struct _drmMMListHead
87 for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \ 94 for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \
88 (__item) != (__list); \ 95 (__item) != (__list); \
89 (__item) = (__temp), (__temp) = (__item)->prev) 96 (__item) = (__temp), (__temp) = (__item)->prev)
97
98#define DRMLISTFOREACHENTRY(__item, __list, __head) \
99 for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head); \
100 &(__item)->__head != (__list); \
101 (__item) = DRMLISTENTRY(typeof(*__item), \
102 (__item)->__head.next, __head))
103
104#define DRMLISTFOREACHENTRYSAFE(__item, __temp, __list, __head) \
105 for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head), \
106 (__temp) = DRMLISTENTRY(typeof(*__item), \
107 (__item)->__head.next, __head); \
108 &(__item)->__head != (__list); \
109 (__item) = (__temp), \
110 (__temp) = DRMLISTENTRY(typeof(*__item), \
111 (__temp)->__head.next, __head))
112
113#define DRMLISTJOIN(__list, __join) if (!DRMLISTEMPTY(__list)) { \
114 (__list)->next->prev = (__join); \
115 (__list)->prev->next = (__join)->next; \
116 (__join)->next->prev = (__list)->prev; \
117 (__join)->next = (__list)->next; \
118}