From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 1EFD4E07 for ; Wed, 18 May 2016 13:05:16 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 07C0029BB4; Wed, 18 May 2016 13:03:39 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: bruce.richardson@intel.com, stephen@networkplumber.org, keith.wiles@intel.com Date: Wed, 18 May 2016 13:04:45 +0200 Message-Id: <1463569496-31086-25-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1463569496-31086-1-git-send-email-olivier.matz@6wind.com> References: <1460629199-32489-1-git-send-email-olivier.matz@6wind.com> <1463569496-31086-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v3 24/35] mempool: introduce a function to free a pool 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: Wed, 18 May 2016 11:05:17 -0000 Introduce rte_mempool_free() that: - unlink the mempool from the global list if it is found - free all the memory chunks using their free callbacks - free the internal ring - free the memzone containing the mempool Currently this function is only used in error cases when creating a new mempool, but it will be made public later in the patch series. Signed-off-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 891458a..4aff53b 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -622,6 +622,35 @@ rte_mempool_populate_default(struct rte_mempool *mp) return ret; } +/* free a mempool */ +static void +rte_mempool_free(struct rte_mempool *mp) +{ + struct rte_mempool_list *mempool_list = NULL; + struct rte_tailq_entry *te; + + if (mp == NULL) + return; + + mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list); + rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); + /* find out tailq entry */ + TAILQ_FOREACH(te, mempool_list, next) { + if (te->data == (void *)mp) + break; + } + + if (te != NULL) { + TAILQ_REMOVE(mempool_list, te, next); + rte_free(te); + } + rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + + rte_mempool_free_memchunks(mp); + rte_ring_free(mp->ring); + rte_memzone_free(mp->mz); +} + /* * Create the mempool over already allocated chunk of memory. * That external memory buffer can consists of physically disjoint pages. @@ -781,13 +810,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, exit_unlock: rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK); - if (mp != NULL) { - rte_mempool_free_memchunks(mp); - rte_ring_free(mp->ring); - } - rte_free(te); - if (mz != NULL) - rte_memzone_free(mz); + rte_mempool_free(mp); return NULL; } -- 2.8.0.rc3