From d87493378d29d9dee3cb1ba13c84790d028b2d40 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 28 May 2019 13:03:25 +0200 Subject: [PATCH] env: added spdk_mempool_obj_iter As the name suggests, this function iterates through all elements of the mempool invoking a callback function on each one. It's particularly useful when deinitializing mempool that requires freeing resources tied to each element (e.g. allocated through spdk_mempool_create_ctor). Change-Id: I3da1fee527a36bf99f0b0e2dd3d6f9297422ff25 Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455971 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- include/spdk/env.h | 12 ++++++++++++ lib/env_dpdk/env.c | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/include/spdk/env.h b/include/spdk/env.h index 25f1542a96..cb9f42b05b 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -430,6 +430,18 @@ void spdk_mempool_put_bulk(struct spdk_mempool *mp, void **ele_arr, size_t count */ size_t spdk_mempool_count(const struct spdk_mempool *pool); +/** + * Iterate through all elements of the pool and call a function on each one. + * + * \param mp Memory pool to iterate on. + * \param obj_cb Function to call on each element. + * \param obj_cb_arg Opaque pointer passed to the callback function. + * + * \return Number of elements iterated. + */ +uint32_t spdk_mempool_obj_iter(struct spdk_mempool *mp, spdk_mempool_obj_cb_t obj_cb, + void *obj_cb_arg); + /** * Get the number of dedicated CPU cores utilized by this env abstraction. * diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 0421ade73c..dbd746dc8e 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -288,6 +288,14 @@ spdk_mempool_count(const struct spdk_mempool *pool) return rte_mempool_avail_count((struct rte_mempool *)pool); } +uint32_t +spdk_mempool_obj_iter(struct spdk_mempool *mp, spdk_mempool_obj_cb_t obj_cb, + void *obj_cb_arg) +{ + return rte_mempool_obj_iter((struct rte_mempool *)mp, (rte_mempool_obj_cb_t *)obj_cb, + obj_cb_arg); +} + bool spdk_process_is_primary(void) {