changeset 7:299cc57f332b

prototype of fifo version.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Wed, 06 Jan 2010 11:28:15 +0900
parents 51c3a631a7bc
children 07fab8c367b2
files Fifo/TaskManager.cbc Fifo/TaskManager.h Fifo/TaskManager.o TaskManagerAbst.cbc taskinit.cbc
diffstat 5 files changed, 53 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/Fifo/TaskManager.cbc	Fri Dec 25 17:55:24 2009 +0900
+++ b/Fifo/TaskManager.cbc	Wed Jan 06 11:28:15 2010 +0900
@@ -23,6 +23,7 @@
 extern __code executed (TaskManager *manager, ListIter *iter, Task *task);
 extern __code finishTask (TaskManager *manager, Task *task);
 extern __code noEvent (TaskManager *manager);
+extern __code searchStartTask(TaskManager *manager);
 
 
 /* for Debug.  */
@@ -41,6 +42,7 @@
 	goto startTaskManager();
 }
 
+// TODO: some codes are moved to TaskManagerAbst.
 /*
  *   Initialization
  */
@@ -56,35 +58,6 @@
 	scheduler = schedEntry;
 	goto searchStartTask(manager);
 }
-/*
- *  Start first task
- */
-__code
-searchStartTask(TaskManager *manager)
-{
-	int i=0;
-	goto searchStartTask_1(manager, i);
-}
-__code
-searchStartTask_1(TaskManager *manager, int i)
-{
-	if (tasktypes[i].flag & F_STARTER ) {
-		goto startTask(manager, i);
-	} else {
-		goto searchStartTask_1(manager, i+1);
-	}
-}
-__code
-startTask(TaskManager *manager, int i)
-{
-	Task *task;
-	task = createTask(i, "start task");
-	taskSetData(task, NULL, 0, NULL, 0);
-	taskSpawn(manager, task);
-
-	goto checkEvent_real(manager);
-}
-
 
 __code
 executeTask(TaskManager *manager, ListIter *iter, Task *task)
@@ -111,13 +84,13 @@
 {
 	SchedTask *stask;
 	Task *task;
-	printTasks(manager);
+	//printTasks(manager);
 	if (manager->exitTasks) {
 		stask = _listGetnthData(manager->exitTasks, 0);
 		manager->exitTasks = _listRemove(manager->exitTasks, stask);
 		task = stask->task;
 		free(stask);
-		__DEBUG("task[%p] finished.\n", task->rbuff);
+		__DEBUG("task[%d] finished.\n", task->id);
 		goto finishTask(manager, task);
 	/*} else if (manager->newtasks) { */
 	} else {
@@ -125,6 +98,12 @@
 	}
 }
 
+__code
+exitTaskManager(TaskManager *manager)
+{
+	__DEBUG("all tasks finished!\n");
+	exit(0);
+}
 
 
 /*
--- a/Fifo/TaskManager.h	Fri Dec 25 17:55:24 2009 +0900
+++ b/Fifo/TaskManager.h	Wed Jan 06 11:28:15 2010 +0900
@@ -14,7 +14,7 @@
 
 typedef struct _TaskManager {
 	List *waitingList;  // list of tasks waiting for others.
-	//List *activeList;
+	List *activeList;
 	List *schedTasks;	// list of schedtasks executing now.
 	List *exitTasks;	// list of schedtasks which finished.
 	SchedTask *running;
Binary file Fifo/TaskManager.o has changed
--- a/TaskManagerAbst.cbc	Fri Dec 25 17:55:24 2009 +0900
+++ b/TaskManagerAbst.cbc	Wed Jan 06 11:28:15 2010 +0900
@@ -6,6 +6,7 @@
 
 extern __code checkEvent(TaskManager *);
 extern __code executeTask(TaskManager*, ListIter*, Task*);
+extern __code exitTaskManager(TaskManager*);
 
 typedef List TaskList;
 
@@ -41,6 +42,9 @@
 __code finishTask_iter (TaskManager *manager, Task *task, ListIter *iter);
 __code finishTask_end (TaskManager *manager, Task *task);
 void setData (Task *task, void *rbuff, size_t rs, void *wbuff, size_t ws);
+__code searchStartTask(TaskManager *manager);
+__code searchStartTask_1(TaskManager *manager, int i);
+__code startTask(TaskManager *manager, int i);
 
 __code
 initTaskManager(__code(*ret)(TaskManager*,void*), void *arg)
@@ -50,6 +54,36 @@
 	goto ret(manager, arg);
 }
 
+/*
+ *  Start first task
+ */
+__code
+searchStartTask(TaskManager *manager)
+{
+	int i=0;
+	goto searchStartTask_1(manager, i);
+}
+__code
+searchStartTask_1(TaskManager *manager, int i)
+{
+	if (tasktypes[i].flag & F_STARTER ) {
+		goto startTask(manager, i);
+	} else {
+		goto searchStartTask_1(manager, i+1);
+	}
+}
+__code
+startTask(TaskManager *manager, int i)
+{
+	Task *task;
+	task = createTask(i, "start task");
+	taskSetData(task, NULL, 0, NULL, 0);
+	taskSpawn(manager, task);
+
+	goto checkEvent(manager);
+}
+
+
 __code
 start(TaskManager *manager)
 {
@@ -72,6 +106,8 @@
 noEvent(TaskManager *manager)
 {
 	ListIter *iter;
+	if (!manager->waitingList && !manager->activeList)
+		goto exitTaskManager(manager);
 	iter = _listIterator(manager->waitingList);
 	goto getTask(manager, iter);
 }
@@ -96,7 +132,7 @@
 executed(TaskManager *manager, ListIter *iter, Task *task)
 {
 	manager->waitingList = _listIterRemoveCurrent(iter);
-	//manager->activeList = _listAddFirst(manager->activeList, task);
+	manager->activeList = _listAddFirst(manager->activeList, task);
 	goto getTask(manager, iter);
 }
 /*
@@ -109,7 +145,7 @@
 {
 	ListIter *iter;
 
-	//manager->activeList = _listRemove(manager->activeList, task);
+	manager->activeList = _listRemove(manager->activeList, task);
 	iter = _listIterator(task->waiter);
 	goto finishTask_iter(manager, task, iter);
 }
--- a/taskinit.cbc	Fri Dec 25 17:55:24 2009 +0900
+++ b/taskinit.cbc	Wed Jan 06 11:28:15 2010 +0900
@@ -1,13 +1,17 @@
 #include "Task.h"
 #include "taskinit.h"
 
+
 const int max_tasktype = MAX_TASKCLASS;
+extern __code nojob(void *, void *, void *);
 
 #undef DEFINETASKTYPE
 #define DEFINETASKTYPE(_var, _code0, _name, _type) \
 	{ _code0, _name, _type }, 
 
 const TaskType tasktypes[] = {
+	{ nojob, "no jobs", F_NONE },
+	{ nojob, "no jobs", F_NONE },
 	#include "task.def"
 };