From: Pablo de Lara Date: Fri, 22 Jul 2016 14:02:01 +0000 (+0100) Subject: eal: add tailq safe iterator macro X-Git-Tag: spdx-start~6099 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=954d6cf5741e2a3efb7f97852833a1ee0a1f165a;p=dpdk.git eal: add tailq safe iterator macro Removing/freeing elements elements within a TAILQ_FOREACH loop is not safe. FreeBSD defines TAILQ_FOREACH_SAFE macro, which permits these operations safely. This patch defines this macro for Linux systems, where it is not defined. Signed-off-by: Pablo de Lara --- diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h index 4a686e68a8..cc3c0f1de4 100644 --- a/lib/librte_eal/common/include/rte_tailq.h +++ b/lib/librte_eal/common/include/rte_tailq.h @@ -155,6 +155,14 @@ void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \ rte_panic("Cannot initialize tailq: %s\n", t.name); \ } +/* This macro permits both remove and free var within the loop safely.*/ +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + #ifdef __cplusplus } #endif