ソースを参照

Add list_for_each_entry_safe.

tags/v0.9.3
Michael Brown 18年前
コミット
7cd0390013
1個のファイルの変更16行の追加1行の削除
  1. 16
    1
      src/include/gpxe/list.h

+ 16
- 1
src/include/gpxe/list.h ファイルの表示

@@ -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 */

読み込み中…
キャンセル
保存