diff mbox

[PATCHv4,06/10] linux-generic: buffer_pool: add term_global

Message ID 1424793647-28572-7-git-send-email-robking@cisco.com
State Accepted
Commit 7fa3ac5d82f311e4d42749cd1d0208729af97921
Headers show

Commit Message

Robbie King Feb. 24, 2015, 4 p.m. UTC
From: Yan Sonming <yan.songming@linaro.org>

Signed-off-by: Yan Songming <yan.songming@linaro.org>
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
Signed-off-by: Robbie King <robking@cisco.com>
---
 platform/linux-generic/include/odp_internal.h |  1 +
 platform/linux-generic/odp_init.c             |  5 +++++
 platform/linux-generic/odp_pool.c             | 30 ++++++++++++++++++++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index c6da30b..c82012d 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -39,6 +39,7 @@  int odp_shm_init_global(void);
 int odp_shm_init_local(void);
 
 int odp_pool_init_global(void);
+int odp_pool_term_global(void);
 
 int odp_pktio_init_global(void);
 int odp_pktio_term_global(void);
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index f15485f..b09e9b3 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -103,6 +103,11 @@  int odp_term_global(void)
 		rc = -1;
 	}
 
+	if (odp_pool_term_global()) {
+		ODP_ERR("ODP buffer pool term failed.\n");
+		rc = -1;
+	}
+
 	return rc;
 }
 
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 422ff2b..441429a 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -55,6 +55,7 @@  typedef struct pool_table_t {
 
 /* The pool table */
 static pool_table_t *pool_tbl;
+static const char SHM_DEFAULT_NAME[] = "odp_buffer_pools";
 
 /* Pool entry pointers (for inlining) */
 void *pool_entry_ptr[ODP_CONFIG_POOLS];
@@ -67,7 +68,7 @@  int odp_pool_init_global(void)
 	uint32_t i;
 	odp_shm_t shm;
 
-	shm = odp_shm_reserve("odp_pools",
+	shm = odp_shm_reserve(SHM_DEFAULT_NAME,
 			      sizeof(pool_table_t),
 			      sizeof(pool_entry_t), 0);
 
@@ -95,6 +96,33 @@  int odp_pool_init_global(void)
 	return 0;
 }
 
+int odp_pool_term_global(void)
+{
+	int i;
+	pool_entry_t *pool;
+	int ret = 0;
+	int rc = 0;
+
+	for (i = 0; i < ODP_CONFIG_POOLS; i++) {
+		pool = get_pool_entry(i);
+
+		POOL_LOCK(&pool->s.lock);
+		if (pool->s.pool_shm != ODP_SHM_INVALID) {
+			ODP_ERR("Not destroyed pool: %s\n", pool->s.name);
+			rc = -1;
+		}
+		POOL_UNLOCK(&pool->s.lock);
+	}
+
+	ret = odp_shm_free(odp_shm_lookup(SHM_DEFAULT_NAME));
+	if (ret < 0) {
+		ODP_ERR("shm free failed for %s", SHM_DEFAULT_NAME);
+		rc = -1;
+	}
+
+	return rc;
+}
+
 /**
  * Pool creation
  */