diff mbox

[PATCHv4,05/10] linux-generic: queue: add term_global

Message ID 1424793647-28572-6-git-send-email-robking@cisco.com
State Accepted
Commit a4853519985b63e6f716cbf4ca22f402ef635a23
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_queue.c            | 38 +++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index 83b0beb..c6da30b 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -48,6 +48,7 @@  int odp_classification_init_global(void);
 int odp_classification_term_global(void);
 
 int odp_queue_init_global(void);
+int odp_queue_term_global(void);
 
 int odp_crypto_init_global(void);
 int odp_crypto_term_global(void);
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 966009a..f15485f 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -98,6 +98,11 @@  int odp_term_global(void)
 		rc = -1;
 	}
 
+	if (odp_queue_term_global()) {
+		ODP_ERR("ODP queue term failed.\n");
+		rc = -1;
+	}
+
 	return rc;
 }
 
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index 6806a95..b945e03 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -128,6 +128,32 @@  int odp_queue_init_global(void)
 	return 0;
 }
 
+int odp_queue_term_global(void)
+{
+	int ret = 0;
+	int rc = 0;
+	queue_entry_t *queue;
+	int i;
+
+	for (i = 0; i < ODP_CONFIG_QUEUES; i++) {
+		queue = &queue_tbl->queue[i];
+		LOCK(&queue->s.lock);
+		if (queue->s.status != QUEUE_STATUS_FREE) {
+			ODP_ERR("Not destroyed queue: %s\n", queue->s.name);
+			rc = -1;
+		}
+		UNLOCK(&queue->s.lock);
+	}
+
+	ret = odp_shm_free(odp_shm_lookup("odp_queues"));
+	if (ret < 0) {
+		ODP_ERR("shm free failed for odp_queues");
+		rc = -1;
+	}
+
+	return rc;
+}
+
 odp_queue_type_t odp_queue_type(odp_queue_t handle)
 {
 	queue_entry_t *queue;
@@ -217,9 +243,17 @@  int odp_queue_destroy(odp_queue_t handle)
 	queue = queue_to_qentry(handle);
 
 	LOCK(&queue->s.lock);
-	if (queue->s.status == QUEUE_STATUS_FREE || queue->s.head != NULL) {
+	if (queue->s.status == QUEUE_STATUS_FREE) {
 		UNLOCK(&queue->s.lock);
-		return -1; /* Queue is already free or not empty */
+		ODP_ERR("queue_destroy: queue \"%s\" already free\n",
+			queue->s.name);
+		return -1;
+	}
+	if (queue->s.head != NULL) {
+		UNLOCK(&queue->s.lock);
+		ODP_ERR("queue_destroy: queue \"%s\" not empty\n",
+			queue->s.name);
+		return -1;
 	}
 
 	queue->s.enqueue = queue_enq_dummy;