diff mbox

[PATCHv2,3/3] Add odp_buffer_pool_destroy() implementation

Message ID 1417547823-16522-3-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Dec. 2, 2014, 7:17 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/odp_buffer_pool.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index fa72972..0004726 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -374,6 +374,32 @@  int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl,
 	return 0;
 }
 
+int odp_buffer_pool_destroy(odp_buffer_pool_t pool_hdl)
+{
+	uint32_t pool_id = pool_handle_to_index(pool_hdl);
+	pool_entry_t *pool = get_pool_entry(pool_id);
+
+	if (pool == NULL)
+		return -1;
+
+	LOCK(&pool->s.lock);
+
+	if (pool->s.pool_shm == ODP_SHM_INVALID ||
+	    odp_atomic_load_u32(&pool->s.bufcount) > 0 ||
+	    pool->s.flags.predefined) {
+		UNLOCK(&pool->s.lock);
+		return -1;
+	}
+
+	if (!pool->s.flags.user_supplied_shm)
+		odp_shm_free(pool->s.pool_shm);
+
+	pool->s.pool_shm = ODP_SHM_INVALID;
+	UNLOCK(&pool->s.lock);
+
+	return 0;
+}
+
 odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size)
 {
 	pool_entry_t *pool = odp_pool_to_entry(pool_hdl);