Browse Source

Add list_for_each_entry_safe.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
7cd0390013
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      src/include/gpxe/list.h

+ 16
- 1
src/include/gpxe/list.h View File

138
  * @v member	The name of the list_struct within the struct
138
  * @v member	The name of the list_struct within the struct
139
  */
139
  */
140
 #define list_for_each_entry( pos, head, member )			      \
140
 #define list_for_each_entry( pos, head, member )			      \
141
-	for ( pos = list_entry ( (head)->next, typeof ( *pos ), member);      \
141
+	for ( pos = list_entry ( (head)->next, typeof ( *pos ), member );     \
142
 	      &pos->member != (head);					      \
142
 	      &pos->member != (head);					      \
143
 	      pos = list_entry ( pos->member.next, typeof ( *pos ), member ) )
143
 	      pos = list_entry ( pos->member.next, typeof ( *pos ), member ) )
144
 
144
 
145
+/**
146
+ * Iterate over entries in a list, safe against deletion of entries
147
+ *
148
+ * @v pos	The type * to use as a loop counter
149
+ * @v tmp	Another type * to use for temporary storage
150
+ * @v head	The head for your list
151
+ * @v member	The name of the list_struct within the struct
152
+ */
153
+#define list_for_each_entry_safe( pos, tmp, head, member )		      \
154
+	for ( pos = list_entry ( (head)->next, typeof ( *pos ), member ),     \
155
+	      tmp = list_entry ( pos->member.next, typeof ( *tmp ), member ); \
156
+	      &pos->member != (head);					      \
157
+	      pos = tmp,						      \
158
+	      tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
159
+
145
 #endif /* _GPXE_LIST_H */
160
 #endif /* _GPXE_LIST_H */

Loading…
Cancel
Save