Module: xenomai-3
Branch: next
Commit: c35e76631e22a17b3f1387e7e95efa08b8accc96
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c35e76631e22a17b3f1387e7e95efa08b8accc96

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Sep 28 18:26:38 2016 +0200

boilerplate/list: add list_{prev, next}_entry() accessors

---

 include/boilerplate/private-list.h |   18 ++++++++++++++++++
 include/boilerplate/shared-list.h  |   24 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/include/boilerplate/private-list.h 
b/include/boilerplate/private-list.h
index f5aafac..72f1e4c 100644
--- a/include/boilerplate/private-list.h
+++ b/include/boilerplate/private-list.h
@@ -146,6 +146,24 @@ static inline int pvlist_heading_p(const struct pvholder 
*holder,
 #define pvlist_last_entry(list, type, member)                  \
        pvlist_entry((list)->head.prev, type, member)
 
+#define pvlist_prev_entry(pos, list, member)                           \
+       ({                                                              \
+               typeof(*pos) *__prev = NULL;                            \
+               if ((list)->head.next != &(pos)->member)                \
+                       __prev = pvlist_entry((pos)->member.prev,       \
+                                             typeof(*pos), member);    \
+               __prev;                                                 \
+       })
+
+#define pvlist_next_entry(pos, list, member)                           \
+       ({                                                              \
+               typeof(*pos) *__next = NULL;                            \
+               if ((list)->head.prev != &(pos)->member)                \
+                       __next = pvlist_entry((pos)->member.next,       \
+                                             typeof(*pos), member);    \
+               __next;                                                 \
+       })
+
 #define pvlist_pop_entry(list, type, member) ({                                
\
                        struct pvholder *__holder = pvlist_pop(list);   \
                        pvlist_entry(__holder, type, member); })
diff --git a/include/boilerplate/shared-list.h 
b/include/boilerplate/shared-list.h
index 0f88d6f..741dfc0 100644
--- a/include/boilerplate/shared-list.h
+++ b/include/boilerplate/shared-list.h
@@ -245,6 +245,30 @@ static inline int list_heading_p(const struct holder 
*holder,
 #define list_last_entry(list, type, member)                    \
        __list_last_entry(__main_heap, list, type, member)
 
+#define __list_prev_entry(heap, pos, list, member)                     \
+       ({                                                              \
+               typeof(*pos) *__prev = NULL;                            \
+               if ((list)->head.next != __hoff(heap, &(pos)->member))  \
+                       __prev = list_entry(__hptr((heap),              \
+                          (pos)->member.prev), typeof(*pos), member);  \
+               __prev;                                                 \
+       })
+
+#define list_prev_entry(pos, list, member)                             \
+       __list_prev_entry(__main_heap, pos, list, member)
+
+#define __list_next_entry(heap, pos, list, member)                     \
+       ({                                                              \
+               typeof(*pos) *__next = NULL;                            \
+               if ((list)->head.prev != __hoff(heap, &(pos)->member))  \
+                       __next = list_entry(__hptr((heap),              \
+                          (pos)->member.next), typeof(*pos), member);  \
+               __next;                                                 \
+       })
+
+#define list_next_entry(pos, list, member)                             \
+       __list_next_entry(__main_heap, pos, list, member)
+
 #define __list_pop_entry(heap, list, type, member) ({                  \
                        struct holder *__holder = __list_pop((heap), list); \
                        list_entry(__holder, type, member); })


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to