view src/Fifo/Scheduler.cbc @ 8:07fab8c367b2

made src directory and move all source files into it. support autocont and automake tools.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 08 Jan 2010 14:40:49 +0900
parents Fifo/Scheduler.cbc@91a07e20e06d
children
line wrap: on
line source

//#include "Task.h"
#include <stdint.h>
#include <stdlib.h>
#include "TaskManager.h"
#include "List.h"

enum wait{
	NOWAIT=0,
	WAIT=1,
};
extern __code checkNewCode(TaskScheduler *, enum wait);

__code (*scheduler)(void*,Taskrun,void*,void*);

typedef List SchedTaskList;
#define addSchedTask(a,b) (SchedTaskList*)_listAddFirst((List*)(a),(void*)(b))
#define removeTask(a,b) (SchedTaskList*)_listRemove((List*)(a),(void*)(b))
// inline functionのがいいか

__code schedEntry(TaskScheduler *tsched, Taskrun nextcode, void *rbuff, void *wbuff);

extern void *allocate(size_t);

#if 0
__code
addCode(TaskScheduler *tsched, ID id, Taskrun code0, void *rbuff, void *wbuff)
{
	SchedTask *newst;
	newst = allocate(sizeof(SchedTask)); //これはAbstractLayerで生成してもいいのだが…
	newst->nextcode = code0;
	newst->rbuff = rbuff; //taskの遷移で引数が変化しないならいならい
	newst->wbuff = wbuff;

	/* regist new task to schedtasks list.  */
	tsched->schedtasks = addSchedTask(tsched->schedtasks, newst);

	goto selectCode(tsched);
}
#endif

__code
selectCode(TaskScheduler *tsched)
{
	SchedTask *task;
	if (tsched->schedtasks) {
		task = (SchedTask*)_listGetLastData(tsched->schedtasks);
		tsched->running = task;

		/* goto user-defined task.  */
		goto task->nextcode(tsched, task->task->rbuff, task->task->wbuff);
	} else {
		/* no task we have.  */
		//goto checkNewCode();
		goto noCode(tsched);
	}
}

__code
schedEntry(TaskScheduler *tsched, Taskrun nextcode, void *rbuff, void *wbuff)
{
	/* schedulerd  */
	if ( nextcode==NULL ) {
		/* the task finished.  */
		tsched->schedtasks =
			_listRemove(tsched->schedtasks, tsched->running);
		tsched->exittasks =
			_listAddFirst(tsched->exittasks, tsched->running);
		goto selectCode(tsched);
		/*
		ID id = tsched->running->id;
		tsched->schedtasks =
			removeTask(tsched->schedtasks, tsched->running);
		free(tsched->running);
		tsched->running = NULL;
		goto exitCode(tsched, id);
		*/
	} else {
		/* save the next code segment for the task.  */
		tsched->running->nextcode = nextcode;
		tsched->running->rbuff = rbuff;
		tsched->running->wbuff = wbuff;
		/* move last task to first to be fair.  */
		tsched->schedtasks = _listMoveLasttoFirst(tsched->schedtasks);
		goto selectCode(tsched, NOWAIT);
	}
}