From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id D929C5A86 for ; Thu, 26 Mar 2015 22:14:57 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 26 Mar 2015 14:14:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,475,1422950400"; d="scan'208";a="546924840" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 26 Mar 2015 14:14:56 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t2QLEtdl028392; Thu, 26 Mar 2015 21:14:55 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t2QLEtig027298; Thu, 26 Mar 2015 21:14:55 GMT Received: (from bricha3@localhost) by sivswdev01.ir.intel.com with id t2QLEshD027294; Thu, 26 Mar 2015 21:14:54 GMT From: Bruce Richardson To: dev@dpdk.org Date: Thu, 26 Mar 2015 21:14:54 +0000 Message-Id: <1427404494-27256-1-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2015 21:14:58 -0000 The logic used in the condition check before freeing an mbuf is sometimes confusing, so explain it in a proper comment. Signed-off-by: Bruce Richardson --- lib/librte_mbuf/rte_mbuf.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 17ba791..0265172 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -764,6 +764,16 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) { __rte_mbuf_sanity_check(m, 0); + /* + * Check to see if this is the last reference to the mbuf. + * Note: the double check here is deliberate. If the ref_cnt is "atomic" + * the call to "refcnt_update" is a very expensive operation, so we + * don't want to call it in the case where we know we are the holder + * of the last reference to this mbuf i.e. ref_cnt == 1. + * If however, ref_cnt != 1, it's still possible that we may still be + * the final decrementer of the count, so we need to check that + * result also, to make sure the mbuf is freed properly. + */ if (likely (rte_mbuf_refcnt_read(m) == 1) || likely (rte_mbuf_refcnt_update(m, -1) == 0)) { -- 2.1.0