summaryrefslogtreecommitdiff
path: root/list.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-05-21 14:39:40 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-05-21 16:33:34 +0300
commit72ec206080350e75a87780895f246f5c4f52e790 (patch)
tree76a4813d2adf5b054d6a322142bd6ac9542bd44d /list.h
parent12c8541a416a73e989f536f2358c369301524825 (diff)
events: Import event handling library from omap3-isp-live
The omap3-isp-live project [1] includes a generic event handling library that implements a select-based loop. Instead of reinventing the wheel, import the library and use it. The original license hasn't been modified, and includes both GPL-2.0+ and LGPL-2.1+ code. The sole copyright owner is Laurent Pinchart. [1] git://git.ideasonboard.org/omap3-isp-live.git Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'list.h')
-rw-r--r--list.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/list.h b/list.h
new file mode 100644
index 0000000..8854c6e
--- /dev/null
+++ b/list.h
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Double Linked Lists
+ *
+ * Copyright (C) 2018 Laurent Pinchart
+ *
+ * This file comes from the omap3-isp-live project
+ * (git://git.ideasonboard.org/omap3-isp-live.git)
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ */
+
+#ifndef __LIST_H
+#define __LIST_H
+
+#include <stddef.h>
+
+struct list_entry {
+ struct list_entry *prev;
+ struct list_entry *next;
+};
+
+static inline void list_init(struct list_entry *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline int list_empty(struct list_entry *list)
+{
+ return list->next == list;
+}
+
+static inline void list_append(struct list_entry *entry, struct list_entry *list)
+{
+ entry->next = list;
+ entry->prev = list->prev;
+ list->prev->next = entry;
+ list->prev = entry;
+}
+
+static inline void list_prepend(struct list_entry *entry, struct list_entry *list)
+{
+ entry->next = list->next;
+ entry->prev = list;
+ list->next->prev = entry;
+ list->next = entry;
+}
+
+static inline void list_insert_after(struct list_entry *entry, struct list_entry *after)
+{
+ list_prepend(entry, after);
+}
+
+static inline void list_insert_before(struct list_entry *entry, struct list_entry *before)
+{
+ list_append(entry, before);
+}
+
+static inline void list_remove(struct list_entry *entry)
+{
+ entry->prev->next = entry->next;
+ entry->next->prev = entry->prev;
+}
+
+#define list_entry(entry, type, member) \
+ (type *)((char *)(entry) - offsetof(type, member))
+
+#define list_first_entry(list, type, member) \
+ list_entry((list)->next, type, member)
+
+#define list_last_entry(list, type, member) \
+ list_entry((list)->prev, type, member)
+
+#define list_for_each(entry, list) \
+ for (entry = (list)->next; entry != (list); entry = entry->next)
+
+#define list_for_each_entry(entry, list, member) \
+ for (entry = list_entry((list)->next, typeof(*entry), member); \
+ &entry->member != (list); \
+ entry = list_entry(entry->member.next, typeof(*entry), member))
+
+#define list_for_each_safe(entry, __next, list) \
+ for (entry = (list)->next, __next = entry->next; entry != (list); \
+ entry = __next, __next = entry->next)
+
+#define list_for_each_entry_safe(entry, __next, list, member) \
+ for (entry = list_entry((list)->next, typeof(*entry), member), \
+ __next = list_entry(entry->member.next, typeof(*entry), member); \
+ &entry->member != (list); \
+ entry = __next, __next = list_entry(entry->member.next, typeof(*entry), member))
+
+#endif /* __LIST_H */