[Cbe-oss-dev] [PATCH 3/5] MARS: yield in task queue push/pop busy loop

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


Call sched_yield() inside the busy loop on the host-side
to wait in push and pop routines. This allows other
processes to run more generously on the host while
waiting in the busy loop.

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

---
 src/host/lib/mars_task_queue.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

--- a/src/host/lib/mars_task_queue.c
+++ b/src/host/lib/mars_task_queue.c
@@ -35,6 +35,8 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <sched.h>
+
 #include "mars/mars_task_queue.h"
 #include "mars/mars_workload_queue.h"
 #include "mars/mars.h"
@@ -168,10 +170,12 @@ static int push(struct mars_task_queue *
 
 	do {
 		/* wait until queue is not full */
-		while (*(volatile uint32_t *)&queue->count == queue->depth) {
+		while (queue->count == queue->depth) {
 			/* only try so return busy */
 			if (try)
 				return MARS_ERROR_BUSY;
+
+			sched_yield();
 		}
 
 		mars_mutex_lock((struct mars_mutex *)queue);
@@ -245,10 +249,12 @@ static int pop(struct mars_task_queue *q
 
 	do {
 		/* wait until queue has data */
-		while (!*(volatile uint32_t *)&queue->count) {
+		while (!queue->count) {
 			/* only try so return busy */
 			if (try)
 				return MARS_ERROR_BUSY;
+
+			sched_yield();
 		}
 
 		mars_mutex_lock((struct mars_mutex *)queue);





More information about the cbe-oss-dev mailing list