Bladeren bron

[list] Add list_check_contains()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 jaren geleden
bovenliggende
commit
df58a19015
1 gewijzigde bestanden met toevoegingen van 19 en 0 verwijderingen
  1. 19
    0
      src/include/ipxe/list.h

+ 19
- 0
src/include/ipxe/list.h Bestand weergeven

@@ -212,4 +212,23 @@ static inline int list_empty ( const struct list_head *list ) {
212 212
 	      pos = tmp,						      \
213 213
 	      tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
214 214
 
215
+/**
216
+ * Check list contains a specified entry
217
+ *
218
+ * @v entry		Entry
219
+ * @v head		List head
220
+ * @v member		Name of list field within iterator's type
221
+ */
222
+#define list_check_contains( entry, head, member ) do {		\
223
+	if ( ASSERTING ) {					\
224
+		typeof ( entry ) tmp;				\
225
+		int found = 0;					\
226
+		list_for_each_entry ( tmp, head, member ) {	\
227
+			if ( tmp == entry )			\
228
+				found = 1;			\
229
+		}						\
230
+		assert ( found );				\
231
+	}							\
232
+	} while ( 0 )
233
+
215 234
 #endif /* _IPXE_LIST_H */

Laden…
Annuleren
Opslaan