summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPablo de Lara <pablo.de.lara.guarch@intel.com>2016-07-22 15:02:01 +0100
committerThomas Monjalon <thomas.monjalon@6wind.com>2016-07-22 17:38:59 +0200
commit954d6cf5741e2a3efb7f97852833a1ee0a1f165a (patch)
tree7d97cf0968f4963311611a1874f2d5720649a2c3 /lib
parentfe7b933b7ae0eccad4cae5937da30356fcc087d2 (diff)
downloaddpdk-954d6cf5741e2a3efb7f97852833a1ee0a1f165a.zip
dpdk-954d6cf5741e2a3efb7f97852833a1ee0a1f165a.tar.gz
dpdk-954d6cf5741e2a3efb7f97852833a1ee0a1f165a.tar.xz
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 <pablo.de.lara.guarch@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/librte_eal/common/include/rte_tailq.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h
index 4a686e6..cc3c0f1 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