summaryrefslogtreecommitdiffstats
path: root/src/include/gpxe/list.h
diff options
context:
space:
mode:
authorMichael Brown2006-05-16 16:14:31 +0200
committerMichael Brown2006-05-16 16:14:31 +0200
commit7cd03900136f80c7ba17637e7394313ad96f0b32 (patch)
tree8405804b52b18052ac3c26fbd4bc3f84f564a48c /src/include/gpxe/list.h
parentAdded generic device model. (diff)
downloadipxe-7cd03900136f80c7ba17637e7394313ad96f0b32.tar.gz
ipxe-7cd03900136f80c7ba17637e7394313ad96f0b32.tar.xz
ipxe-7cd03900136f80c7ba17637e7394313ad96f0b32.zip
Add list_for_each_entry_safe.
Diffstat (limited to 'src/include/gpxe/list.h')
-rw-r--r--src/include/gpxe/list.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/include/gpxe/list.h b/src/include/gpxe/list.h
index 7c6042b2..0e65901c 100644
--- a/src/include/gpxe/list.h
+++ b/src/include/gpxe/list.h
@@ -138,8 +138,23 @@ static inline int list_empty ( const struct list_head *head ) {
* @v member The name of the list_struct within the struct
*/
#define list_for_each_entry( pos, head, member ) \
- for ( pos = list_entry ( (head)->next, typeof ( *pos ), member); \
+ for ( pos = list_entry ( (head)->next, typeof ( *pos ), member ); \
&pos->member != (head); \
pos = list_entry ( pos->member.next, typeof ( *pos ), member ) )
+/**
+ * Iterate over entries in a list, safe against deletion of entries
+ *
+ * @v pos The type * to use as a loop counter
+ * @v tmp Another type * to use for temporary storage
+ * @v head The head for your list
+ * @v member The name of the list_struct within the struct
+ */
+#define list_for_each_entry_safe( pos, tmp, head, member ) \
+ for ( pos = list_entry ( (head)->next, typeof ( *pos ), member ), \
+ tmp = list_entry ( pos->member.next, typeof ( *tmp ), member ); \
+ &pos->member != (head); \
+ pos = tmp, \
+ tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
+
#endif /* _GPXE_LIST_H */