X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fstruct%2Flist.h;h=96b71b4fdb05fab95f136eb96c66b0199af767dd;hb=d603ad8d35758a54f6cb08a7f8c16f6327ea86e0;hp=91fe63fb50ad194ed52d111c0999b4b486fc55df;hpb=9b851504d2822d5d10b9894dd09706a39232faad;p=bertos.git diff --git a/bertos/struct/list.h b/bertos/struct/list.h index 91fe63fb..96b71b4f 100644 --- a/bertos/struct/list.h +++ b/bertos/struct/list.h @@ -216,6 +216,21 @@ typedef struct _PriNode (n) = (TYPEOF_OR_VOIDPTR(n))(((Node *)(n))->pred) \ ) +/** + * Iterate on the list safely against node removal. + * + * This macro generates a "for" statement using the following parameters: + * \param n Node pointer to be used in each iteration. + * \param p Temporal storage for the iterator. + * \param l Pointer to list. + */ +#define FOREACH_NODE_SAFE(n, p, l) \ + for( \ + (n) = (TYPEOF_OR_VOIDPTR(n))LIST_HEAD(l), (p) = ((Node *)(n))->succ; \ + ((Node *)(n))->succ; \ + (n) = (p), (p) = (TYPEOF_OR_VOIDPTR(n))(((Node *)(n))->succ) \ + ) + /** Initialize a list. */ #define LIST_INIT(l) \ do { \