Explorar el Código

Add list_for_each_entry_safe.

tags/v0.9.3
Michael Brown hace 18 años
padre
commit
7cd0390013
Se han modificado 1 ficheros con 16 adiciones y 1 borrados
  1. 16
    1
      src/include/gpxe/list.h

+ 16
- 1
src/include/gpxe/list.h Ver fichero

@@ -138,8 +138,23 @@ static inline int list_empty ( const struct list_head *head ) {
138 138
  * @v member	The name of the list_struct within the struct
139 139
  */
140 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 142
 	      &pos->member != (head);					      \
143 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 160
 #endif /* _GPXE_LIST_H */

Loading…
Cancelar
Guardar