# HG changeset patch # User kent # Date 1263028429 -32400 # Node ID 5f65da34f4f3dbba990a574bf3d12f9a7110ae63 # Parent f06fb0370cafcdc3cca9158a8f663f9bf05f81a0 add runnable pthread mode. diff -r f06fb0370caf -r 5f65da34f4f3 configure --- a/configure Fri Jan 08 20:00:01 2010 +0900 +++ b/configure Sat Jan 09 18:13:49 2010 +0900 @@ -738,6 +738,7 @@ ac_user_opts=' enable_option_checking enable_dependency_tracking +enable_debug with_mode ' ac_precious_vars='build_alias @@ -1380,6 +1381,7 @@ --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors + --enable-debug enable debug mode Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -5633,6 +5635,17 @@ +# Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then + enableval=$enable_debug; case "${enableval}" in + yes) + CPPFLAGS="${CPPFLAGS} -DDEBUG" + CFLAGS="-g3 -O0" + ;; + *) CPPFLAGS="${CPPFLAGS} -UDEBUG";; + esac +fi + #AC_ARG_ENABLE([fifo], #[ --enable-fifo use only fifo scheduler], #[case "${enableval}" in diff -r f06fb0370caf -r 5f65da34f4f3 configure.ac --- a/configure.ac Fri Jan 08 20:00:01 2010 +0900 +++ b/configure.ac Sat Jan 09 18:13:49 2010 +0900 @@ -1,8 +1,8 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ([2.63]) -AC_INIT([TaskManager], [0.1], [kent@cr.ie.u-ryukyu.ac.jp]) +AC_PREREQ(2.63) +AC_INIT([TaskManager],[0.1],[kent@cr.ie.u-ryukyu.ac.jp]) AM_INIT_AUTOMAKE(TaskManager, 0.1) AC_CONFIG_SRCDIR([memo.txt]) AC_CONFIG_HEADERS(config.h) @@ -32,6 +32,15 @@ AC_CHECK_FUNCS([strdup]) +AC_ARG_ENABLE([debug], + [ --enable-debug enable debug mode], + [case "${enableval}" in + yes) + CPPFLAGS="${CPPFLAGS} -DDEBUG" + CFLAGS="-g3 -O0" + ;; + *) CPPFLAGS="${CPPFLAGS} -UDEBUG";; + esac],) #AC_ARG_ENABLE([fifo], #[ --enable-fifo use only fifo scheduler], #[case "${enableval}" in diff -r f06fb0370caf -r 5f65da34f4f3 examples/Makefile.am --- a/examples/Makefile.am Fri Jan 08 20:00:01 2010 +0900 +++ b/examples/Makefile.am Sat Jan 09 18:13:49 2010 +0900 @@ -12,5 +12,6 @@ #testmanager_LDADD = ../src/libTaskManager.a LDADD = ../src/libTaskManager.a AM_CPPFLAGS = -I$(top_srcdir)/src/userinclude +AM_LDFLAGS = -lpthread diff -r f06fb0370caf -r 5f65da34f4f3 examples/Makefile.in --- a/examples/Makefile.in Fri Jan 08 20:00:01 2010 +0900 +++ b/examples/Makefile.in Sat Jan 09 18:13:49 2010 +0900 @@ -168,6 +168,7 @@ #testmanager_LDADD = ../src/libTaskManager.a LDADD = ../src/libTaskManager.a AM_CPPFLAGS = -I$(top_srcdir)/src/userinclude +AM_LDFLAGS = -lpthread all: all-am .SUFFIXES: @@ -181,9 +182,9 @@ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/Makefile + $(AUTOMAKE) --foreign examples/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff -r f06fb0370caf -r 5f65da34f4f3 src/Fifo/SchedTask.h --- a/src/Fifo/SchedTask.h Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Fifo/SchedTask.h Sat Jan 09 18:13:49 2010 +0900 @@ -1,7 +1,6 @@ #ifndef _SCHEDTASK_H #define _SCHEDTASK_H -#include "user.h" #include "Task.h" typedef struct _SchedTask { diff -r f06fb0370caf -r 5f65da34f4f3 src/Makefile.am --- a/src/Makefile.am Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Makefile.am Sat Jan 09 18:13:49 2010 +0900 @@ -6,14 +6,14 @@ $(CbCCOMPILE) -c -o $@ $< lib_LIBRARIES = libTaskManager.a -libTaskManager_a_SOURCES = TaskManagerAbst.cbc List.c Debug.h +libTaskManager_a_SOURCES = TaskManagerAbst.cbc List.c Debug.h Queue.c if USE_FIFO libTaskManager_a_SOURCES += Fifo/TaskManager.cbc AM_CPPFLAGS = -I$(srcdir)/Fifo else if USE_PTHREAD - libTaskManager_a_SOURCES += pthread/TaskManager.cbc + libTaskManager_a_SOURCES += pthread/TaskManager.cbc pthread/ThreadManager.cbc AM_CPPFLAGS = -I$(srcdir)/pthread endif endif diff -r f06fb0370caf -r 5f65da34f4f3 src/Makefile.in --- a/src/Makefile.in Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Makefile.in Sat Jan 09 18:13:49 2010 +0900 @@ -32,7 +32,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : @USE_FIFO_TRUE@am__append_1 = Fifo/TaskManager.cbc -@USE_FIFO_FALSE@@USE_PTHREAD_TRUE@am__append_2 = pthread/TaskManager.cbc +@USE_FIFO_FALSE@@USE_PTHREAD_TRUE@am__append_2 = pthread/TaskManager.cbc pthread/ThreadManager.cbc subdir = src DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in @@ -57,12 +57,14 @@ libTaskManager_a_AR = $(AR) $(ARFLAGS) libTaskManager_a_LIBADD = am__libTaskManager_a_SOURCES_DIST = TaskManagerAbst.cbc List.c Debug.h \ - Fifo/TaskManager.cbc pthread/TaskManager.cbc + Queue.c Fifo/TaskManager.cbc pthread/TaskManager.cbc \ + pthread/ThreadManager.cbc am__dirstamp = $(am__leading_dot)dirstamp @USE_FIFO_TRUE@am__objects_1 = Fifo/TaskManager.$(OBJEXT) -@USE_FIFO_FALSE@@USE_PTHREAD_TRUE@am__objects_2 = pthread/TaskManager.$(OBJEXT) +@USE_FIFO_FALSE@@USE_PTHREAD_TRUE@am__objects_2 = pthread/TaskManager.$(OBJEXT) \ +@USE_FIFO_FALSE@@USE_PTHREAD_TRUE@ pthread/ThreadManager.$(OBJEXT) am_libTaskManager_a_OBJECTS = TaskManagerAbst.$(OBJEXT) List.$(OBJEXT) \ - $(am__objects_1) $(am__objects_2) + Queue.$(OBJEXT) $(am__objects_1) $(am__objects_2) libTaskManager_a_OBJECTS = $(am_libTaskManager_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -173,7 +175,7 @@ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) lib_LIBRARIES = libTaskManager.a -libTaskManager_a_SOURCES = TaskManagerAbst.cbc List.c Debug.h \ +libTaskManager_a_SOURCES = TaskManagerAbst.cbc List.c Debug.h Queue.c \ $(am__append_1) $(am__append_2) @USE_FIFO_FALSE@@USE_PTHREAD_TRUE@AM_CPPFLAGS = -I$(srcdir)/pthread @USE_FIFO_TRUE@AM_CPPFLAGS = -I$(srcdir)/Fifo @@ -191,9 +193,9 @@ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/Makefile + $(AUTOMAKE) --foreign src/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -256,6 +258,8 @@ @: > pthread/$(DEPDIR)/$(am__dirstamp) pthread/TaskManager.$(OBJEXT): pthread/$(am__dirstamp) \ pthread/$(DEPDIR)/$(am__dirstamp) +pthread/ThreadManager.$(OBJEXT): pthread/$(am__dirstamp) \ + pthread/$(DEPDIR)/$(am__dirstamp) libTaskManager.a: $(libTaskManager_a_OBJECTS) $(libTaskManager_a_DEPENDENCIES) -rm -f libTaskManager.a $(libTaskManager_a_AR) libTaskManager.a $(libTaskManager_a_OBJECTS) $(libTaskManager_a_LIBADD) @@ -265,11 +269,13 @@ -rm -f *.$(OBJEXT) -rm -f Fifo/TaskManager.$(OBJEXT) -rm -f pthread/TaskManager.$(OBJEXT) + -rm -f pthread/ThreadManager.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/List.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Queue.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff -r f06fb0370caf -r 5f65da34f4f3 src/Queue.c --- a/src/Queue.c Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Queue.c Sat Jan 09 18:13:49 2010 +0900 @@ -8,8 +8,17 @@ * * Usage: * + * |Blocks|Unblocks| + * ---------+------+--------+ + * Insert | put | offer | + * Remove | take | poll | + * Examine| peek | | + * + * But, insert operation dosen't block in this implementation. + * */ + Queue * createQueue(int blocking) { @@ -19,48 +28,73 @@ newQ->tail = NULL; //newQ->mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_init(&newQ->mutex, NULL); + pthread_cond_init(&newQ->cond, NULL); return newQ; } void -Qoffer(Queue *queue, void *data) +destroyQueue(Queue *queue) +{ + List *l; + l = queue->head; + while (l) { + List *n; + n = l->next; + free(l); + l = n; + } + pthread_mutex_destroy(&queue->mutex); + pthread_cond_destroy(&queue->cond); + free(queue); +} + +void +queuePut(Queue *queue, void *data) { List *oldhead, *newlist; newlist = malloc(sizeof(struct _List)); + newlist->data = data; + pthread_mutex_lock(&queue->mutex); - pthread_mutex_lock(&queue->mutex); oldhead = queue->head; if (oldhead) { oldhead->prev = newlist; + } else { + queue->tail = newlist; } newlist->next = oldhead; newlist->prev = NULL; queue->head = newlist; queue->length++; + pthread_cond_broadcast(&queue->cond); pthread_mutex_unlock(&queue->mutex); return ; } void * -Qpoll(Queue *queue) +queueTake(Queue *queue) { List *first, *second; void *data; pthread_mutex_lock(&queue->mutex); - first = queue->tail; - if (!first) { - pthread_mutex_unlock(&queue->mutex); - return NULL; + + while (!queue->tail) { + pthread_cond_wait(&queue->cond, &queue->mutex); } + first = queue->tail; second = first->prev; data = first->data; free(first); - second->next = NULL; + if (second) { + second->next = NULL; + } else { + queue->head = NULL; + } queue->tail = second; queue->length--; @@ -68,31 +102,59 @@ return data; } +void +queueOffer(Queue *queue, void *data) +{ + queuePut(queue, data); +} + +void * +queuePoll(Queue *queue) +{ + List *first, *second; + void *data; + + pthread_mutex_lock(&queue->mutex); + + if (!queue->tail) { + pthread_mutex_unlock(&queue->mutex); + return NULL; + } + + first = queue->tail; + second = first->prev; + data = first->data; + free(first); + + if (second) { + second->next = NULL; + } else { + queue->head = NULL; + } + queue->tail = second; + queue->length--; + + pthread_mutex_unlock(&queue->mutex); + return data; +} + +void * +queuePeek(Queue *queue) +{ + List *first, *second; + void *data; + + pthread_mutex_lock(&queue->mutex); + + if (!queue->tail) { + data = NULL; + } else { + data = queue->tail->data; + } + + pthread_mutex_unlock(&queue->mutex); + return data; +} -/* - * for DEBUG -int -RingCheck(List *head) -{ - List *cur = head; - - if (cur->prev->next!=cur) return 0; - if (cur->next->prev!=cur) return 0; - do { - if (cur->prev->next!=cur) return 0; - if (cur->next->prev!=cur) return 0; - cur = cur->prev; - } while (cur!=head); - - if (cur->prev->next!=cur) return 0; - if (cur->next->prev!=cur) return 0; - cur = cur->next; - if (cur->prev->next!=cur) return 0; - if (cur->next->prev!=cur) return 0; - - return 1; -} - */ - diff -r f06fb0370caf -r 5f65da34f4f3 src/Queue.h --- a/src/Queue.h Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Queue.h Sat Jan 09 18:13:49 2010 +0900 @@ -8,10 +8,15 @@ struct _List *tail; unsigned int length; pthread_mutex_t mutex; + pthread_cond_t cond; } Queue; Queue * createQueue(int blocking); -void Qoffer(Queue *queue, void *data); -void * Qpoll(Queue *queue); +void destroyQueue(Queue *queue); +void queueOffer(Queue *queue, void *data); +void * queuePoll(Queue *queue); +void queuePut(Queue *queue, void *data); +void * queueTake(Queue *queue); +void * queuePeek(Queue *queue); #endif /* !_QUEUE_H */ diff -r f06fb0370caf -r 5f65da34f4f3 src/Task.h --- a/src/Task.h Fri Jan 08 20:00:01 2010 +0900 +++ b/src/Task.h Sat Jan 09 18:13:49 2010 +0900 @@ -3,8 +3,8 @@ // included by user. #include "List.h" -#include "interface.h" +typedef __code (*Taskrun)(void*, void*, void*); #define F_NONE 0x000 #define F_STARTER 0x001 diff -r f06fb0370caf -r 5f65da34f4f3 src/TaskManagerAbst.cbc --- a/src/TaskManagerAbst.cbc Fri Jan 08 20:00:01 2010 +0900 +++ b/src/TaskManagerAbst.cbc Sat Jan 09 18:13:49 2010 +0900 @@ -59,6 +59,7 @@ Task *task; task = createTask(i, "start task"); taskSetData(task, NULL, 0, NULL, 0); + task->cpu = MAIN; manager->waitingList = _listAddFirst(manager->waitingList, task); goto checkEvent(manager); diff -r f06fb0370caf -r 5f65da34f4f3 src/pthread/TaskManager.cbc --- a/src/pthread/TaskManager.cbc Fri Jan 08 20:00:01 2010 +0900 +++ b/src/pthread/TaskManager.cbc Sat Jan 09 18:13:49 2010 +0900 @@ -1,7 +1,10 @@ +#include "List.h" +#include "Queue.h" #include "TaskManager.h" #include "Task.h" #include "Debug.h" +typedef __code (*Scheduler)(struct _UserManager*,Taskrun,void*,void*); typedef struct _UserManager { Scheduler scheduler; @@ -13,7 +16,7 @@ /* defined in TaskManagerAbst. */ extern Task *createTask(int, char *); extern void taskSetData(Task*, void*, int, void*, int); -extern void taskSpawn(TaskManager*, Task*); +extern void taskSpawn(UserManager*, Task*); /* declarations of code segment. */ int main (int argc, char **argv); @@ -24,8 +27,8 @@ __code executeTask (TaskManager *manager, ListIter *iter, Task *task); __code checkEvent (TaskManager *manager); __code checkEvent_real (TaskManager *manager); -__code selectCode (TaskManager *manager); -__code schedEntry (TaskManager *manager, Taskrun nextcode, void *rbuff, void *wbuff); +static __code selectCode (TaskManager *manager); +static __code schedEntry(UserManager *user, Taskrun nextcode, void *rbuff, void *wbuff); /* external code segments. */ extern __code executed (TaskManager *manager, ListIter *iter, Task *task); @@ -38,10 +41,6 @@ void printTasks(TaskManager *manager); -/* Global variable for user task. */ -__code (*scheduler)(TaskManager*, Taskrun, void*, void*); - - int @@ -58,11 +57,13 @@ startTaskManager() { TaskManager *manager; + UserManager *umanager; manager = malloc(sizeof(TaskManager)); umanager= malloc(sizeof(UserManager)); manager->waitingList = NULL; manager->activeList = NULL; - manager->finishtaskQ = createQueue(); + manager->schedTasks = NULL; + manager->finishtaskQ = createQueue(1); manager->user = umanager; umanager->manager = manager; @@ -76,22 +77,23 @@ __code startThreadManager(TaskManager *manager) { - manager->thread_num = 3//TODO ; + manager->thread_num = 3;//TODO manager->thread = malloc(sizeof(ThreadManager)*manager->thread_num); + manager->thread_round = 0; goto startThreadManager_iter(manager, 0); } __code startThreadManager_iter(TaskManager *manager, int i) { - if (i < thread_num) { + if (i < manager->thread_num) { manager->thread[i].finishtaskQ = manager->finishtaskQ; - manager->thread[i].newtaskQ = createQueue(); + manager->thread[i].newtaskQ = createQueue(1); manager->thread[i].thread_id = i; manager->thread[i].finishFlag = 0; manager->thread[i].schedTasks = NULL; manager->thread[i].running = NULL; pthread_create(&manager->thread[i].thread, NULL, threadbase, &manager->thread[i]); - goto startThreadManager(manager, i+1); + goto startThreadManager_iter(manager, i+1); } else { goto searchStartTask(manager); } @@ -112,7 +114,11 @@ manager->schedTasks = _listAddFirst(manager->schedTasks, stask); } else { - Qoffer(manager->thread[manager->thread_round].newtaskQ, task); + // どのthreadに渡すかが問題 + // とりあえずラウンドロビン + queueOffer(manager->thread[manager->thread_round].newtaskQ, task); + manager->thread_round++; + manager->thread_round %= manager->thread_num; } goto executed(manager, iter, task); } @@ -126,13 +132,10 @@ __code checkEvent_real(TaskManager *manager) { - SchedTask *stask; Task *task; //printTasks(manager); - stask = Qpoll(manager->finishtaskQ); - if (stask) { - task = stask->task; - free(stask); + task = queuePoll(manager->finishtaskQ); + if (task) { __DEBUG("task[%d] finished.\n", task->id); goto finishTask(manager, task); /*} else if (manager->newtasks) { */ @@ -178,8 +181,8 @@ /* the task finished. */ manager->schedTasks = _listRemove(manager->schedTasks, manager->running); - Qoffer(manager->finishtaskQ, manager->running); - goto selectCode(manager->manager); + queueOffer(manager->finishtaskQ, manager->running); + goto selectCode(manager); } else { /* save the next code segment for the task. */ manager->running->nextcode = nextcode; @@ -218,14 +221,25 @@ __DEBUGnoF("\n"); _listIterEnd(iter); + /* __DEBUG("exit:\n\t"); iter = _listIterator(manager->exitTasks); while ( (stask=_listIterNext(iter))!=NULL ) { __DEBUGnoF("%d, ", stask->task->id); } + */ __DEBUGnoF("\n"); _listIterEnd(iter); } +void +taskSpawn(UserManager *user, Task *task) +{ + TaskManager *manager = user->manager; + manager->waitingList = _listAddFirst(manager->waitingList, task); + //ablayer->spawnedTasks = _listAddFirst(ablayer->spawnedTasks, task); + return ; +} + diff -r f06fb0370caf -r 5f65da34f4f3 src/pthread/TaskManager.h --- a/src/pthread/TaskManager.h Fri Jan 08 20:00:01 2010 +0900 +++ b/src/pthread/TaskManager.h Sat Jan 09 18:13:49 2010 +0900 @@ -3,34 +3,24 @@ #include #include "List.h" #include "Task.h" -#include "interface.h" +#include "Fifo/SchedTask.h" #include "ThreadManager.h" -typedef struct _SchedTask { - Task *task; - Taskrun nextcode; - void *rbuff; - void *wbuff; -} SchedTask; - typedef struct _TaskManager { List *waitingList; // list of tasks waiting for others. List *activeList; - //List *schedTasks; // list of schedtasks executing now. + List *schedTasks; // list of schedtasks executing now. + SchedTask *running; //List *exitTasks; // list of schedtasks which finished. ThreadManager *thread; // array of thread id. int thread_num; + int thread_round; - Queue finishtaskQ; // Task Queue which shared by TaskManager + Queue *finishtaskQ; // Task Queue which shared by TaskManager // and all ThreadManagers. struct _UserManager *user; // used by user. } TaskManager; -typedef struct _UserManager { - Scheduler scheduler; - TaskManager *manager; -} UserManager; - #endif /* !_TASKMANAGER_H */ diff -r f06fb0370caf -r 5f65da34f4f3 src/pthread/ThreadManager.cbc --- a/src/pthread/ThreadManager.cbc Fri Jan 08 20:00:01 2010 +0900 +++ b/src/pthread/ThreadManager.cbc Sat Jan 09 18:13:49 2010 +0900 @@ -1,3 +1,4 @@ +#include #include #include // TODO: malloc @@ -6,6 +7,7 @@ #include "Fifo/SchedTask.h" #include "ThreadManager.h" +typedef __code (*Scheduler)(struct _UserManager*,Taskrun,void*,void*); typedef struct _UserManager { Scheduler scheduler; @@ -18,6 +20,8 @@ */ } UserManager; +static __code schedEntry(UserManager *user, Taskrun nextcode, void *rbuff, void *wbuff); +static __code selectCode(ThreadManager *manager); void * threadbase(void *args) @@ -25,11 +29,15 @@ ThreadManager *manager = args; UserManager *umanager; - umanager = malloc(sizeof(Usermanager)); + umanager = malloc(sizeof(UserManager)); umanager->scheduler = schedEntry; umanager->threadmanager = manager; manager->user = umanager; + fprintf(stderr, "test\n"); + fflush(stderr); + __DEBUG("ThreadManager:%d started.\n",manager->thread_id); + fflush(stderr); goto threadloop(manager); } @@ -39,6 +47,8 @@ { if (manager->finishFlag) goto exitThread(manager); + else if (!manager->schedTasks) + goto waitNewTask(manager); else goto checkNewTask(manager); } @@ -46,7 +56,7 @@ __code exitThread(ThreadManager *manager) { - __DEBUG("thread whose id is %d finished!", manager->thread_id); + __DEBUG("thread whose id is %d finished!\n", manager->thread_id); free(manager->user); pthread_exit(0); } @@ -55,20 +65,39 @@ checkNewTask(ThreadManager *manager) { Task *task; - task = Qpoll(newtaskQ); + SchedTask *stask; + + __DEBUG("thread:%d.\n",manager->thread_id); + task = queuePoll(manager->newtaskQ); + if (task) { - SchedTask *stask; stask = malloc(sizeof(SchedTask)); stask->task = task; stask->nextcode = tasktypes[task->typeid].code; stask->rbuff = task->rbuff; stask->wbuff = task->wbuff; + manager->schedTasks = _listAddFirst(manager->schedTasks, stask); + } - manager->schedTasks = _listAddFirst(manager->schedTasks, stask); - goto checkNewTask(manager); - } else { - goto selectCode(manager); - } + goto selectCode(manager); +} + +__code +waitNewTask(ThreadManager *manager) +{ + Task *task; + SchedTask *stask; + __DEBUG("thread:%d.\n",manager->thread_id); + + task = queueTake(manager->newtaskQ); + stask = malloc(sizeof(SchedTask)); + stask->task = task; + stask->nextcode = tasktypes[task->typeid].code; + stask->rbuff = task->rbuff; + stask->wbuff = task->wbuff; + + manager->schedTasks = _listAddFirst(manager->schedTasks, stask); + goto selectCode(manager); } /* @@ -100,9 +129,14 @@ /* schedulerd */ if ( nextcode==NULL ) { /* the task finished. */ + Task *task; + task = manager->running->task; + manager->schedTasks = _listRemove(manager->schedTasks, manager->running); - Qoffer(manager->finishtaskQ, manager->running->task); + free(manager->running); + manager->running = NULL; + queueOffer(manager->finishtaskQ, task); //goto selectCode(manager); goto threadloop(manager); } else { diff -r f06fb0370caf -r 5f65da34f4f3 src/pthread/ThreadManager.h --- a/src/pthread/ThreadManager.h Fri Jan 08 20:00:01 2010 +0900 +++ b/src/pthread/ThreadManager.h Sat Jan 09 18:13:49 2010 +0900 @@ -4,6 +4,8 @@ #include #include +#include "Fifo/SchedTask.h" + typedef struct _ThreadManager { pthread_t thread; int thread_id; @@ -11,13 +13,16 @@ // These Queue should be changed to Blocking-Queue. // Now, when the thread has no task, he wait by busy loop. - Queue newtaskQ; - Queue finishtaskQ; + Queue *newtaskQ; + Queue *finishtaskQ; - List schedTasks; - SchedTask running; + List *schedTasks; + SchedTask *running; struct _UserManager *user; } ThreadManager; +/* ThreadManager entry point. */ +void * threadbase(void *); + #endif /* _THREADMANAGER_H */