DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Cc: helin.zhang@intel.com, Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [dpdk-dev] [PATCH v2 1/2] eal: add tailq safe iterator macro
Date: Fri, 22 Jul 2016 15:02:01 +0100	[thread overview]
Message-ID: <1469196122-168989-2-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1469196122-168989-1-git-send-email-pablo.de.lara.guarch@intel.com>

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>
---
 lib/librte_eal/common/include/rte_tailq.h | 8 ++++++++
 1 file changed, 8 insertions(+)

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
-- 
2.7.4

  reply	other threads:[~2016-07-22 14:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-22 13:08 [dpdk-dev] [PATCH 0/2] Safe tailq element removal in i40e driver Pablo de Lara
2016-07-22 13:08 ` [dpdk-dev] [PATCH 1/2] eal: add tailq safe iterator macro Pablo de Lara
2016-07-22 13:08 ` [dpdk-dev] [PATCH 2/2] net/i40e: avoid unsafe tailq element removal Pablo de Lara
2016-07-22 14:02 ` [dpdk-dev] [PATCH v2 0/2] Safe tailq element removal in i40e driver Pablo de Lara
2016-07-22 14:02   ` Pablo de Lara [this message]
2016-07-22 14:02   ` [dpdk-dev] [PATCH v2 2/2] net/i40e: fix unsafe tailq element removal Pablo de Lara
2016-07-22 14:56     ` Thomas Monjalon
2016-07-22 16:23   ` [dpdk-dev] [PATCH v2 0/2] Safe tailq element removal in i40e driver Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469196122-168989-2-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=dev@dpdk.org \
    --cc=helin.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).