From 5a933d4beed80dbf8123e1c140e18d0c0263a1c5 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 29 Jan 2002 16:28:52 +0000 Subject: [PATCH] Add list_iterate that's safe with deletions. --- lib/datastruct/list.h | 5 ++++- libdm/datastruct/list.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/datastruct/list.h b/lib/datastruct/list.h index cfda137ab..5f2e14c11 100644 --- a/lib/datastruct/list.h +++ b/lib/datastruct/list.h @@ -47,7 +47,10 @@ static inline int list_empty(struct list *head) { } #define list_iterate(v, head) \ - for (v = (head)->n; v != head; v = v->n) + for (v = (head)->n; v != head; v = v->n) + +#define list_iterate_safe(v, t, head) \ + for (v = (head)->n, t = v->n; v != head; v = t, t = v->n) static inline int list_size(struct list *head) { int s = 0; diff --git a/libdm/datastruct/list.h b/libdm/datastruct/list.h index cfda137ab..5f2e14c11 100644 --- a/libdm/datastruct/list.h +++ b/libdm/datastruct/list.h @@ -47,7 +47,10 @@ static inline int list_empty(struct list *head) { } #define list_iterate(v, head) \ - for (v = (head)->n; v != head; v = v->n) + for (v = (head)->n; v != head; v = v->n) + +#define list_iterate_safe(v, t, head) \ + for (v = (head)->n, t = v->n; v != head; v = t, t = v->n) static inline int list_size(struct list *head) { int s = 0;