Pārlūkot izejas kodu

[list] Add list_check_contains()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 gadus atpakaļ
vecāks
revīzija
df58a19015
1 mainītis faili ar 19 papildinājumiem un 0 dzēšanām
  1. 19
    0
      src/include/ipxe/list.h

+ 19
- 0
src/include/ipxe/list.h Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt