diff mbox

[PATCHv4,3/3] linux-generic: schedule: make sure SCHED queues get freed by the scheduler

Message ID 1426678594-29398-4-git-send-email-ciprian.barbu@linaro.org
State New
Headers show

Commit Message

Ciprian Barbu March 18, 2015, 11:36 a.m. UTC
ODP_QUEUE_TYPE_SCHED queues only get marked as destroyed, they need to be
removed from the pri_queues of the linux-generic scheduler

Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
---
v3:
- check ev is valid
- use already set pri_q like Maxim suggested
v2:
- removed #if 1 and trailing whitespaces
 platform/linux-generic/odp_schedule.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
index dd65168..ea60639 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -153,7 +153,35 @@  int odp_schedule_term_global(void)
 
 	for (i = 0; i < ODP_CONFIG_SCHED_PRIOS; i++) {
 		for (j = 0; j < QUEUES_PER_PRIO; j++) {
-			if (odp_queue_destroy(sched->pri_queue[i][j])) {
+			odp_queue_t pri_q = sched->pri_queue[i][j];
+
+			for (;;) {
+				odp_event_t ev = odp_queue_deq(pri_q);
+				odp_buffer_t desc_buf;
+				queue_desc_t *desc;
+				odp_queue_t queue;
+
+				if (ev == ODP_EVENT_INVALID)
+					break;
+
+				desc_buf = odp_buffer_from_event(ev);
+				if (desc_buf == ODP_BUFFER_INVALID) {
+					ODP_ERR("Sched term: Invalid event.\n");
+					rc = -1;
+					break;
+				}
+
+				desc  = odp_buffer_addr(desc_buf);
+				queue = desc->queue;
+				/* Let deq_multi_destroy do the job */
+				if (queue_is_destroyed(queue)) {
+					odp_queue_deq_multi(queue,
+							    sched_local.ev,
+							    MAX_DEQ);
+				}
+			}
+
+			if (odp_queue_destroy(pri_q)) {
 				ODP_ERR("Sched term: Queue destroy fail.\n");
 				rc = -1;
 			}