diff mbox

[PATCHv6,5/7] api: buffer: add pool destroy

Message ID 1418663392-28354-6-git-send-email-taras.kondratiuk@linaro.org
State Accepted
Commit 86e0b5f8e29cc3bdbc14db0c90b104cdbbbbb564
Headers show

Commit Message

Taras Kondratiuk Dec. 15, 2014, 5:09 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 .../linux-generic/include/api/odp_buffer_pool.h    | 18 ++++++++++++
 platform/linux-generic/odp_buffer_pool.c           | 34 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_buffer_pool.h b/platform/linux-generic/include/api/odp_buffer_pool.h
index 4ccdfe6..312b5f6 100644
--- a/platform/linux-generic/include/api/odp_buffer_pool.h
+++ b/platform/linux-generic/include/api/odp_buffer_pool.h
@@ -76,6 +76,24 @@  odp_buffer_pool_t odp_buffer_pool_create(const char *name,
 					 odp_shm_t shm,
 					 odp_buffer_pool_param_t *params);
 
+/**
+ * Destroy a buffer pool previously created by odp_buffer_pool_create()
+ *
+ * @param pool    Handle of the buffer pool to be destroyed
+ *
+ * @retval 0 Success
+ * @retval -1 Failure
+ *
+ * @note This routine destroys a previously created buffer pool. This call
+ * does not destroy any shared memory object passed to
+ * odp_buffer_pool_create() used to store the buffer pool contents. The caller
+ * takes responsibility for that. If no shared memory object was passed as
+ * part of the create call, then this routine will destroy any internal shared
+ * memory objects associated with the buffer pool. Results are undefined if
+ * an attempt is made to destroy a buffer pool that contains allocated or
+ * otherwise active buffers.
+ */
+int odp_buffer_pool_destroy(odp_buffer_pool_t pool);
 
 /**
  * Find a buffer pool by name
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index f19bee0..e2511af 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -390,6 +390,40 @@  odp_buffer_pool_t odp_buffer_pool_lookup(const char *name)
 	return ODP_BUFFER_POOL_INVALID;
 }
 
+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;
+
+	POOL_LOCK(&pool->s.lock);
+
+	/* Call fails if pool is not allocated or predefined*/
+	if (pool->s.pool_shm == ODP_SHM_INVALID ||
+	    pool->s.flags.predefined) {
+		POOL_UNLOCK(&pool->s.lock);
+		return -1;
+	}
+
+	/* Make sure local cache is empty */
+	flush_cache(&local_cache[pool_id], &pool->s);
+
+	/* Call fails if pool has allocated buffers */
+	if (odp_atomic_load_u32(&pool->s.bufcount) < pool->s.params.num_bufs) {
+		POOL_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;
+	POOL_UNLOCK(&pool->s.lock);
+
+	return 0;
+}
 
 odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size)
 {