summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorweety <[email protected]>2016-05-31 20:23:32 +0800
committerweety <[email protected]>2016-05-31 20:23:32 +0800
commit94e1935f1f2149f4e98098fbd171c3e96acb0e14 (patch)
treec775db6b6c5fdc5c6ae811b44a5791af40784e2a /include
parent714f00679eed2c8d1e758c768cf7af57944a5f08 (diff)
parentc8cfc14b82c633c7153113ac1f753695254d4bd6 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into fixed
Diffstat (limited to 'include')
-rw-r--r--include/rtservice.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/rtservice.h b/include/rtservice.h
index 6de279e63f..ccc63f85e5 100644
--- a/include/rtservice.h
+++ b/include/rtservice.h
@@ -113,6 +113,27 @@ rt_inline int rt_list_isempty(const rt_list_t *l)
#define rt_list_entry(node, type, member) \
((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
+/**
+ * list_for_each_entry - iterate over list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member) \
+ for (pos = rt_list_entry((head)->next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = rt_list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+ rt_list_entry((ptr)->next, type, member)
/*@}*/
#ifdef __cplusplus