summaryrefslogtreecommitdiff
path: root/libdrm_lists.h
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2011-12-17 23:37:20 +1000
committerBen Skeggs <bskeggs@redhat.com>2012-04-14 02:47:04 +1000
commit0d6350002d74848dd3d1e4d28d514a7ac9d580c9 (patch)
tree7160d9cb68222a1ede9b8854c351d203354440b6 /libdrm_lists.h
parentf00efc7ab442f106d3ac7699e80f1f7aee8451f4 (diff)
downloadlibdrm-0d6350002d74848dd3d1e4d28d514a7ac9d580c9.tar.gz
libdrm-0d6350002d74848dd3d1e4d28d514a7ac9d580c9.tar.bz2
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
#define DRMLISTEMPTY(__item) ((__item)->next == (__item))
+#define DRMLISTSINGLE(__list) \
+ (!DRMLISTEMPTY(__list) && ((__list)->next == (__list)->prev))
+
+#define DRMLISTFOREACH(__item, __list) \
+ for ((__item) = (__list)->next; \
+ (__item) != (__list); (__item) = (__item)->next)
+
#define DRMLISTFOREACHSAFE(__item, __temp, __list) \
for ((__item) = (__list)->next, (__temp) = (__item)->next; \
(__item) != (__list); \
@@ -87,3 +94,25 @@ typedef struct _drmMMListHead
for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \
(__item) != (__list); \
(__item) = (__temp), (__temp) = (__item)->prev)
+
+#define DRMLISTFOREACHENTRY(__item, __list, __head) \
+ for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head); \
+ &(__item)->__head != (__list); \
+ (__item) = DRMLISTENTRY(typeof(*__item), \
+ (__item)->__head.next, __head))
+
+#define DRMLISTFOREACHENTRYSAFE(__item, __temp, __list, __head) \
+ for ((__item) = DRMLISTENTRY(typeof(*__item), (__list)->next, __head), \
+ (__temp) = DRMLISTENTRY(typeof(*__item), \
+ (__item)->__head.next, __head); \
+ &(__item)->__head != (__list); \
+ (__item) = (__temp), \
+ (__temp) = DRMLISTENTRY(typeof(*__item), \
+ (__temp)->__head.next, __head))
+
+#define DRMLISTJOIN(__list, __join) if (!DRMLISTEMPTY(__list)) { \
+ (__list)->next->prev = (__join); \
+ (__list)->prev->next = (__join)->next; \
+ (__join)->next->prev = (__list)->prev; \
+ (__join)->next = (__list)->next; \
+}