[Cbe-oss-dev] [PATCH 4/5] MARS: host-side task queue push/pop cleanup

Yuji Mano Yuji.Mano at am.sony.com
Tue Jul 15 10:26:39 EST 2008


Clean up implementation for host-side task queue push
and pop routines to be symmetrical to the MPU-side
implementation of the same routines.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 src/host/lib/mars_task_queue.c |   87 ++++++++++++++++-------------------------
 1 file changed, 35 insertions(+), 52 deletions(-)

--- a/src/host/lib/mars_task_queue.c
+++ b/src/host/lib/mars_task_queue.c
@@ -168,37 +168,31 @@ static int push(struct mars_task_queue *
 	MARS_CHECK_RET(queue->direction == MARS_TASK_EVENT_FLAG_HOST_TO_MPU,
 			MARS_ERROR_STATE);
 
-	do {
-		/* wait until queue is not full */
-		while (queue->count == queue->depth) {
-			/* only try so return busy */
-			if (try)
-				return MARS_ERROR_BUSY;
+	mars_mutex_lock((struct mars_mutex *)queue);
 
-			sched_yield();
-		}
+	/* queue is full so wait */
+	while (queue->count == queue->depth) {
+		mars_mutex_unlock((struct mars_mutex *)queue);
 
-		mars_mutex_lock((struct mars_mutex *)queue);
+		/* only try so return busy */
+		if (try)
+			return MARS_ERROR_BUSY;
 
-		/* check condition again after locking mutex */
-		if (queue->count < queue->depth) {
-			/* copy data into queue */
-			memcpy((void *)queue->push_ea, data, queue->size);
+		while (queue->count == queue->depth)
+			sched_yield();
 
-			/* update queue data */
-			push_update(queue);
+		mars_mutex_lock((struct mars_mutex *)queue);
+	}
 
-			mars_mutex_unlock((struct mars_mutex *)queue);
+	/* copy data into queue */
+	memcpy((void *)queue->push_ea, data, queue->size);
 
-			return MARS_SUCCESS;
-		}
+	/* update queue data */
+	push_update(queue);
 
-		mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock((struct mars_mutex *)queue);
 
-		/* only try so return busy */
-		if (try)
-			return MARS_ERROR_BUSY;
-	} while (1);
+	return MARS_SUCCESS;
 }
 
 int mars_task_queue_push(struct mars_task_queue *queue, const void *data)
@@ -247,43 +241,32 @@ static int pop(struct mars_task_queue *q
 	MARS_CHECK_RET(queue->direction == MARS_TASK_EVENT_FLAG_MPU_TO_HOST,
 			MARS_ERROR_STATE);
 
-	do {
-		/* wait until queue has data */
-		while (!queue->count) {
-			/* only try so return busy */
-			if (try)
-				return MARS_ERROR_BUSY;
+	mars_mutex_lock((struct mars_mutex *)queue);
 
-			sched_yield();
-		}
+	/* queue is empty so wait */
+	while (!queue->count) {
+		mars_mutex_unlock((struct mars_mutex *)queue);
 
-		mars_mutex_lock((struct mars_mutex *)queue);
+		/* only try so return busy */
+		if (try)
+			return MARS_ERROR_BUSY;
 
-		/* check condition again after locking mutex */
-		if (queue->count) {
-			/* copy data from queue */
-			memcpy(data, (void *)queue->pop_ea, queue->size);
-
-			/* only peek so return without removing data entry */
-			if (peek) {
-				mars_mutex_unlock((struct mars_mutex *)queue);
-				return MARS_SUCCESS;
-			}
+		while (!queue->count)
+			sched_yield();
 
-			/* update queue data */
-			pop_update(queue);
+		mars_mutex_lock((struct mars_mutex *)queue);
+	}
 
-			mars_mutex_unlock((struct mars_mutex *)queue);
+	/* copy data from queue */
+	memcpy(data, (void *)queue->pop_ea, queue->size);
 
-			return MARS_SUCCESS;
-		}
+	/* update queue data only if this is not a peek operation */
+	if (!peek)
+		pop_update(queue);
 
-		mars_mutex_unlock((struct mars_mutex *)queue);
+	mars_mutex_unlock((struct mars_mutex *)queue);
 
-		/* only try so return busy */
-		if (try)
-			return MARS_ERROR_BUSY;
-	} while (1);
+	return MARS_SUCCESS;
 }
 
 int mars_task_queue_pop(struct mars_task_queue *queue, void *data)




More information about the cbe-oss-dev mailing list