From: Junyan He <junyan...@intel.com>

We need to add and delete CL objects into container frequently,
so add the list operation to ease this.

Signed-off-by: Junyan He <junyan...@intel.com>
---
 src/cl_utils.h | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/src/cl_utils.h b/src/cl_utils.h
index 77b9bd8..24a71cd 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -355,5 +355,94 @@ static INLINE int atomic_add(atomic_t *v, const int c) {
 static INLINE int atomic_inc(atomic_t *v) { return atomic_add(v, 1); }
 static INLINE int atomic_dec(atomic_t *v) { return atomic_add(v, -1); }
 
-#endif /* __CL_UTILS_H__ */
+/* The list. */
+typedef struct list_head {
+  struct list_head *next, *prev;
+} list_head;
+
+static inline void list_init(struct list_head *head)
+{
+  head->next = head->prev = head;
+}
+static inline void list_add(struct list_head *the_new,
+                            struct list_head *prev, struct list_head *next)
+{
+  next->prev = the_new;
+  the_new->next = next;
+  the_new->prev = prev;
+  prev->next = the_new;
+}
+static inline void list_add_tail(struct list_head *the_new, struct list_head 
*head)
+{
+  list_add(the_new, head->prev, head);
+}
+static inline void list_del(struct list_head *node)
+{
+  node->next->prev = node->prev;
+  node->prev->next = node->next;
+  node->prev = node->next = node;
+}
+static inline void list_replace(struct list_head *the_old, struct list_head 
*the_new)
+{
+  the_new->next = the_old->next;
+  the_new->next->prev = the_new;
+  the_new->prev = the_old->prev;
+  the_new->prev->next = the_new;
+}
+static inline int list_empty(const struct list_head *head)
+{
+  return head->next == head;
+}
+static inline int list_is_last(const struct list_head *list, const struct 
list_head *head)
+{
+  return list->next == head;
+}
+static inline void __list_splice(const struct list_head *list,
+                                 struct list_head *prev, struct list_head 
*next)
+{
+  struct list_head *first = list->next;
+  struct list_head *last = list->prev;
 
+  first->prev = prev;
+  prev->next = first;
+
+  last->next = next;
+  next->prev = last;
+}
+/**
+ * list_splice - join two lists
+ */
+static inline void list_splice(const struct list_head *list, struct list_head 
*head)
+{
+  if (!list_empty(list))
+    __list_splice(list, head, head->next);
+}
+
+/**
+ * list_splice_tail - join two lists, each list being a queue
+ */
+static inline void list_splice_tail(struct list_head *list, struct list_head 
*head)
+{
+  if (!list_empty(list))
+    __list_splice(list, head->prev, head);
+}
+
+#undef offsetof
+#ifdef __compiler_offsetof
+#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
+#endif
+#define container_of(ptr, type, member) ({                      \
+      const typeof( ((type *)0)->member ) *__mptr = (ptr);      \
+      (type *)( (char *)__mptr - offsetof(type,member) ); })
+#define list_entry(ptr, type, member) container_of(ptr, type, member)
+
+#define list_for_each(pos, head) \
+  for (pos = (head)->next; pos != (head); pos = pos->next)
+
+#define list_for_each_safe(pos, n, head)                 \
+  for (pos = (head)->next, n = pos->next; pos != (head); \
+       pos = n, n = pos->next)
+
+#endif /* __CL_UTILS_H__ */
-- 
2.7.4

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth


_______________________________________________
Beignet mailing list
Beignet@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to