view test/manager/testmanager.cbc @ 2:803d6bf22e6d default tip

second commit. it's far to complete..
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Dec 2009 16:19:56 +0900
parents
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>

#include "List.h"
#include "Task.h"
#include "TaskManager.h"

#include "taskinit.h"

#define __DEBUG(f, args...) \
	fprintf(stderr, "in %s: "f, __FUNCTION__, ## args)


extern int main (int, char **);
extern __code teststart ();
__code retinit(TaskManager *, void *);
extern __code checkEvent ();
extern __code executeTask (TaskManager *, ListIter *, Task *);

__code end();


#define NUM 16
Task *tasks[NUM];
int stat[NUM];

__code taskA(Scheduler scheduler, void *rbuff, void *wbuff)
{
	goto scheduler(END, NULL, NULL);
}
__code taskB(Scheduler scheduler, void *rbuff, void *wbuff)
{
	goto scheduler(END, NULL, NULL);
}


int
main(int argc, char **argv)
{
	goto teststart();
	return 0;
}

__code
teststart()
{
	int i;
	/*
	tasks[0] = createTask(TASK_A, NULL);
	tasks[1] = createTask(TASK_B, NULL);
	tasks[2] = createTask(TASK_B, NULL);
	tasks[3] = createTask(TASK_A, NULL);
	tasks[4] = createTask(TASK_B, NULL);
	tasks[5] = createTask(TASK_B, NULL);
	tasks[6] = createTask(TASK_B, NULL);
	taskSetWait(tasks[2], tasks[0]);
	taskSetWait(tasks[3], tasks[0]);
	taskSetWait(tasks[3], tasks[1]);
	taskSetWait(tasks[4], tasks[2]);
	taskSetWait(tasks[5], tasks[2]);
	taskSetWait(tasks[5], tasks[3]);
	taskSetWait(tasks[6], tasks[4]);
	taskSetWait(tasks[6], tasks[5]);
	*/
	for (i=0; i<NUM; i++) {
		tasks[i] = createTask(TASK_A, NULL);
	}
	taskSetWait(tasks[0], tasks[1]);
	for (i=1; 2*i<NUM; i++) {
		taskSetWait(tasks[i], tasks[2*i]);
		if (2*i+1<NUM)
			taskSetWait(tasks[i], tasks[2*i+1]);
	}

	goto initTaskManager(retinit, NULL);
}

__code
retinit(TaskManager *manager, void *arg)
{
	goto checkEvent(manager);
}

__code
checkEvent(TaskManager *manager)
{
	int i;
	static int count=0;
	if (count<NUM) {
		count++;
		__DEBUG("new task %d added\n", NUM-count);
		goto addNewTask(manager, tasks[NUM-count]);
	}
	for (i=0; i<NUM; i++) {
		if (stat[i]==1) {
			stat[i]=2;
			__DEBUG("finish task %d\n", i);
			goto finishTask(manager, tasks[i]);
		}
	}

	for (i=0; i<NUM; i++) {
		if (stat[i]!=2) break;
	}

	if (i==NUM) {
		__DEBUG("all tasks finished.\n");
		goto end();
	}

	__DEBUG("noevent.\n");
	goto noEvent(manager);
}

__code
end()
{
	exit(0);
}

__code
executeTask(TaskManager *manager, ListIter *iter, Task *task)
{
	int i;
	const TaskType *type;
	type = &tasktypes[task->typeid];

	__DEBUG("task %s[%s] is executed.\n", task->name, type->name);
	for (i=0; i<NUM; i++) {
		if (tasks[i]==task) {
			stat[i] = 1;
		}
	}

	goto executed(manager, iter, task);
	//goto code(scheduler, task->rbuff, task->wbuff);
}