diff TaskScheduler.cbc @ 1:aef83aed7a07

scheduler test success.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Sun, 20 Dec 2009 20:46:53 +0900
parents 5b089096921f
children 803d6bf22e6d
line wrap: on
line diff
--- a/TaskScheduler.cbc	Fri Dec 18 21:57:05 2009 +0900
+++ b/TaskScheduler.cbc	Sun Dec 20 20:46:53 2009 +0900
@@ -4,6 +4,11 @@
 #include "TaskScheduler.h"
 #include "List.h"
 
+enum {
+	NOWAIT=0,
+	WAIT=1,
+};
+__code checkNewCode();
 
 typedef List SchedTaskList;
 #define addSchedTask(a,b) (SchedTaskList*)_listAddFirst((List*)(a),(void*)(b))
@@ -57,10 +62,15 @@
 selectCode()
 {
 	SchedTask *task;
-	task = _listGetnthData(schedule->runnable, 0);
-	schedule->running = task;
+	if (schedule->runnable) {
+		task = _listGetLastData(schedule->runnable);
+		schedule->running = task;
 
-	goto task->nextcode((void*)schedEntry, task->rbuff, task->wbuff);
+		goto task->nextcode((void*)schedEntry, task->rbuff, task->wbuff);
+	} else {
+		//goto checkNewCode();
+		goto checkNewCode(WAIT);
+	}
 }
 
 __code
@@ -76,10 +86,14 @@
 		schedule->running = NULL;
 		goto exitCode(id);
 	} else {
+		SchedTaskList list;
+		/* save the next code segment for the task.  */
 		schedule->running->nextcode = nextcode;
 		schedule->running->rbuff = rbuff;
 		schedule->running->wbuff = wbuff;
-		goto checkNewCode();
+		/* move last task to first to be fair.  */
+		schedule->runnable = _listMoveLasttoFirst(schedule->runnable);
+		goto checkNewCode(NOWAIT);
 	}
 }