# HG changeset patch # User Shinji KONO # Date 1280907985 -32400 # Node ID 9989dd7b9ac23e20679520b2f0bed1d56c6eb29d # Parent 6d3c954e510a74c16932e9469815e5efb9cd5cc6 unify all QueueInfo diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/Cell/CellTaskManagerImpl.h --- a/TaskManager/Cell/CellTaskManagerImpl.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/Cell/CellTaskManagerImpl.h Wed Aug 04 16:46:25 2010 +0900 @@ -12,8 +12,8 @@ ~CellTaskManagerImpl(); /* variables */ - TaskListInfoPtr *taskListInfo; - TaskListInfoPtr *speTaskList; // running task + QueueInfo *taskListInfo; + QueueInfo *speTaskList; // running task SpeThreads *speThreads; FifoTaskManagerImpl *ppeManager; diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/Fifo/FifoTaskManagerImpl.cc --- a/TaskManager/Fifo/FifoTaskManagerImpl.cc Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc Wed Aug 04 16:46:25 2010 +0900 @@ -2,7 +2,8 @@ #include #include #include "FifoTaskManagerImpl.h" -#include "TaskListInfo.h" +#include "QueueInfo.h" +#include "TaskList.h" #include "Scheduler.h" #include "SchedTask.h" #include "types.h" @@ -10,6 +11,8 @@ #include "SchedNop.h" #include "SysFunc.h" +extern QueueInfo *taskListPool; + // static void send_alloc_reply(FifoTaskManagerImpl *tm, int id, MainScheduler *s); FifoTaskManagerImpl::~FifoTaskManagerImpl() @@ -36,8 +39,8 @@ mainScheduler->id = 0; set_scheduler(mainScheduler); - taskListInfo = new TaskListInfo; - ppeTaskList = new TaskListInfo; + taskListInfo = new QueueInfo(taskListPool); + ppeTaskList = new QueueInfo(taskListPool); schedTaskManager = new SchedTask(); others = 0; @@ -63,8 +66,8 @@ htaskImpl = tm-> htaskImpl ; waitTaskQueue = tm->waitTaskQueue; - taskListInfo = new TaskListInfo; - ppeTaskList = new TaskListInfo; + taskListInfo = new QueueInfo(taskListPool); + ppeTaskList = new QueueInfo(taskListPool); // schedTaskManager = new SchedTask(); others = tm; @@ -127,7 +130,7 @@ // ppeTaskList は走り終わった ppe の Task の List. // taskListInfo はこれから走る Task の List. // 交換して実行する - TaskListInfoPtr tmp = ppeTaskList; + QueueInfo* tmp = ppeTaskList; ppeTaskList = taskListInfo; taskListInfo = tmp; // ppeTaskList は本来は循環リストなのだけど、実行中は線形リストである。 diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/Fifo/FifoTaskManagerImpl.h --- a/TaskManager/Fifo/FifoTaskManagerImpl.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/Fifo/FifoTaskManagerImpl.h Wed Aug 04 16:46:25 2010 +0900 @@ -13,8 +13,8 @@ /* variables */ int machineNum; - TaskListInfoPtr taskListInfo; - TaskListInfoPtr ppeTaskList; // running task + QueueInfo *taskListInfo; + QueueInfo *ppeTaskList; // running task MailManager *mailManager; MainScheduler *mainScheduler; diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/HTask.h --- a/TaskManager/kernel/ppe/HTask.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/kernel/ppe/HTask.h Wed Aug 04 16:46:25 2010 +0900 @@ -4,7 +4,8 @@ #include "base.h" #include "types.h" #include "Task.h" -#include "TaskQueueInfo.h" +#include "TaskQueue.h" +#include "QueueInfo.h" #include class TaskManagerImpl; @@ -29,8 +30,8 @@ public: BASE_NEW_DELETE(HTask); - TaskQueueInfo *wait_me; // List of task waiting for me - TaskQueueInfo *wait_i; // List of task for which I am waiting + QueueInfo *wait_me; // List of task waiting for me + QueueInfo *wait_i; // List of task for which I am waiting PostFunction post_func; void *post_arg1; void *post_arg2; @@ -53,6 +54,12 @@ Task *next_task_array(int task_id, Task *t); void spawn_task_array(Task *t); + HTask *init(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws) { + init(cmd); + set_input(rbuf, rs); + set_output(wbuf, ws); + return this; + } private: @@ -114,10 +121,12 @@ flag.no_auto_free = 0; } - void init(int cmd) { + void init() { next = prev = NULL; waiter = NULL; + } + void init(int cmd) { command = cmd; param_index = 0; in_index = 0; diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/HTaskInfo.cc --- a/TaskManager/kernel/ppe/HTaskInfo.cc Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -#include -#include -#include "TaskManagerImpl.h" -#include "HTaskInfo.h" -#include "TaskQueueInfo.h" - -// Singleton HTask Pool -HTaskInfo HTaskInfo::taskQueuePool; - -HTaskInfo::HTaskInfo() { - // 最初の一つは自分 - first = last = this; - next = prev = this; - waiter = NULL; -} - -void -HTaskInfo::freePool() { - for(HTaskPtr p = taskQueuePool.waiter; p; ) { - HTaskPtr next = p->waiter; - p->waiter = NULL; - delete p->wait_me; - delete p->wait_i; - free(p); - p = next; - } -} - -int -HTaskInfo::extend_pool(int num) -{ - HTaskPtr q = (HTaskPtr)malloc(sizeof(HTask)*(num+1)); - - // First Queue is previous pool - q->waiter = waiter; waiter = q; - q++; - - /* Connect all free queue in the pool */ - HTaskPtr p = q; - for (; num-- > 0; p++) { - p->waiter = NULL; - p->wait_me = new TaskQueueInfo(); - p->wait_i = new TaskQueueInfo(); - taskQueuePool.addLast(p); - } - - return 0; -} - -/** - * Task をプールから取って来て返す - * - * @param [cmd] タスクコマンド - */ -HTaskPtr -HTaskInfo::create(int cmd) -{ - HTaskPtr q = taskQueuePool.poll(); - if (! q) { - taskQueuePool.extend_pool(64); - q = taskQueuePool.poll(); - } - q->init(cmd); - return q; -} - -HTaskPtr -HTaskInfo::create(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws) -{ - HTaskPtr task = create(cmd); - task->set_input(rbuf, rs); - task->set_output(wbuf, ws); - return task; -} - - -void -HTaskInfo::free_(HTaskPtr q) -{ - q->waiter = NULL; - taskQueuePool.addLast(q); -} - - -/*! - HTaskInfo は空にならない。最低1個は要素が入っていて - 1個目は特別扱いする。getFirst すると first->next を返す - */ - -/*! - 最初の1個は特別扱いなので、それの後に追加していく - */ -void -HTaskInfo::addFirst(HTask* e) -{ - e->prev = first; - e->next = first->next; - first->next->prev = e; - first->next = e; -} - -void -HTaskInfo::addLast(HTask* e) -{ -#ifdef CHECK - if (find(e)) { - fprintf(stderr,"Add duplicate task %0x\n",(int)e); - return; - // ... - } -#endif - e->next = first; - e->prev = last; - last->next = e; - last = e; -} - -HTask* -HTaskInfo::getFirst() -{ - if (empty()) return NULL; - return first->next; -} - -HTask* -HTaskInfo::getLast() -{ - if (empty()) return NULL; - return last; -} - -int -HTaskInfo::remove(HTask* e) -{ -#ifdef CHECK - if (!find(e)) { - fprintf(stderr,"Remove non existing task %0x\n",(int)e); - return 0; - // ... - } -#endif - e->prev->next = e->next; - e->next->prev = e->prev; - - if (first->next == e) { - first->next = e->next; - } - if (last == e) { - last = e->prev; - } - - e->prev = NULL; - e->next = NULL; - - return 1; -} - -/*! - リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 - */ - -HTask* -HTaskInfo::poll() -{ - HTask* e = first->next; - if (e == this) { - return NULL; - } - remove(e); - return e; -} - -void -HTaskInfo::moveToFirst(HTask* e) -{ - remove(e); - addFirst(e); -} - -/*! - リスト内の指定された位置にある要素を返す。 - 要素数を超えた位置を指定した場合 NULL を返す。 - */ - -HTask* -HTaskInfo::get(int index) -{ - HTask* e = first->next; - for (int i = 0; i < index; i++) { - if (e == this) return NULL; - e = e->next; - } - return e; -} - -HTask* -HTaskInfo::find(HTask* task) -{ - HTask* e = first->next; - for(;;) { - if (e == this) return NULL; - if (e == task) break; - e = e->next; - } - return e; -} - -int -HTaskInfo::empty() -{ - return next == this; -} - -HTask* -HTaskInfo::getNext(HTask* q) -{ - if (q->next==this) return NULL; - return q->next; -} - -int -HTaskInfo::length() -{ - int i = 1; - if (empty()) return 0; - HTask* e = first; - while((e = e->next) != this ) i++; - return i; -} - - - - -/* end */ - - diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/HTaskInfo.h --- a/TaskManager/kernel/ppe/HTaskInfo.h Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#ifndef INCLUDED_HTASK_INFO -#define INCLUDED_HTASK_INFO - -#include "Task.h" -#include "HTask.h" - -class HTaskInfo : public HTask { - -public: - /* constructor */ - HTaskInfo(); - - BASE_NEW_DELETE(HTaskInfo); - - /* functions */ - HTaskPtr create(int cmd); - HTaskPtr create(int cmd, memaddr rbuf, int rs, memaddr wbuf, int ws); - - void free_(HTaskPtr queue); - - void addFirst(HTask* e); - void addLast(HTask* e); - HTask* getFirst(); - HTask* getLast(); - int remove(HTask* e); - HTask* poll(); - void moveToFirst(HTask* e); // or use(); - HTask* get(int index); - HTask* find(HTask *task); - int empty(); - void freePool() ; - - // Iterator - HTask* getNext(HTask* q) ; - int length(); - -private: - /* variables */ - - static HTaskInfo taskQueuePool; - HTask* first; - HTask* last; - - /* functions */ - int extend_pool(int num); - void destroy(); -} ; - -#endif diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/QueueInfo.h --- a/TaskManager/kernel/ppe/QueueInfo.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/kernel/ppe/QueueInfo.h Wed Aug 04 16:46:25 2010 +0900 @@ -49,6 +49,7 @@ T* find(T *task); int empty(); void freePool() ; + void freeAll(); // Iterator T* getNext(T* q) ; @@ -290,6 +291,12 @@ return i; } +templatevoid +QueueInfo::freeAll() +{ + T* t; + while((t=poll())) free_(t); +} diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskListInfo.cc --- a/TaskManager/kernel/ppe/TaskListInfo.cc Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,232 +0,0 @@ -#include -#include -#include "types.h" -#include "TaskListInfo.h" - - -// Singleton TaskList Pool -TaskListInfo TaskListInfo::taskListPool; - -TaskListInfo::TaskListInfo() { - // 最初の一つは自分 - first = last = this; - next = prev = this; - waiter = NULL; -} - -void -TaskListInfo::freePool() { - for(TaskListPtr p = taskListPool.waiter; p; ) { - TaskListPtr next = p->waiter; - p->waiter = NULL; - free(p); - p = next; - } -} - -int -TaskListInfo::extend_pool(int num) -{ - TaskListPtr q = (TaskListPtr)malloc(sizeof(TaskList)*(num+1)+DEFAULT_ALIGNMENT); - - // First Queue is previous pool - q->waiter = waiter; waiter = q; - q = (TaskListPtr)ROUND_UP_ALIGN((long)q, DEFAULT_ALIGNMENT); - q++; - - /* Connect all free queue in the pool */ - TaskListPtr p = q; - for (; num-- > 0; p++) { - p->waiter = NULL; - taskListPool.addLast(p); - } - - return 0; -} - -/** - * Task をプールから取って来て返す - * - * @param [cmd] タスクコマンド - */ -TaskListPtr -TaskListInfo::create() -{ - TaskListPtr q = taskListPool.poll(); - if (! q) { - taskListPool.extend_pool(64); - q = taskListPool.poll(); - } - q->init(); - return q; -} - - -void -TaskListInfo::free_(TaskListPtr q) -{ - q->waiter = NULL; - taskListPool.addLast(q); -} - -void -TaskListInfo::freeAll() -{ - TaskListPtr t; - //if (getLast()->next==0) getLast()->next = this; - while((t=poll())) free_(t); -} - - -/*! - TaskListInfo は空にならない。最低1個は要素が入っていて - 1個目は特別扱いする。getFirst すると first->next を返す - */ - -/*! - 最初の1個は特別扱いなので、それの後に追加していく - */ -void -TaskListInfo::addFirst(TaskList* e) -{ - e->prev = first; - e->next = first->next; - first->next->prev = e; - first->next = e; -} - -void -TaskListInfo::addLast(TaskList* e) -{ -#ifdef CHECK - if (find(e)) { - fprintf(stderr,"Add duplicate task %0x\n",(int)e); - return; - // ... - } -#endif - e->next = first; - e->prev = last; - last->next = e; - last = e; -} - -TaskList* -TaskListInfo::getFirst() -{ - if (empty()) return NULL; - return first->next; -} - -TaskList* -TaskListInfo::getLast() -{ - if (empty()) return NULL; - return last; -} - -int -TaskListInfo::remove(TaskList* e) -{ -#ifdef CHECK - if (!find(e)) { - fprintf(stderr,"Remove non existing task %0x\n",(int)e); - return 0; - // ... - } -#endif - e->prev->next = e->next; - e->next->prev = e->prev; - - if (first->next == e) { - first->next = e->next; - } - if (last == e) { - last = e->prev; - } - - e->prev = NULL; - e->next = NULL; - - return 1; -} - -/*! - リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 - */ - -TaskList* -TaskListInfo::poll() -{ - TaskList* e = first->next; - if (e == this) { - return NULL; - } - remove(e); - return e; -} - -void -TaskListInfo::moveToFirst(TaskList* e) -{ - remove(e); - addFirst(e); -} - -/*! - リスト内の指定された位置にある要素を返す。 - 要素数を超えた位置を指定した場合 NULL を返す。 - */ - -TaskList* -TaskListInfo::get(int index) -{ - TaskList* e = first->next; - for (int i = 0; i < index; i++) { - if (e == this) return NULL; - e = e->next; - } - return e; -} - -TaskList* -TaskListInfo::find(TaskList* task) -{ - TaskList* e = first->next; - for(;;) { - if (e == this) return NULL; - if (e == task) break; - e = e->next; - } - return e; -} - -int -TaskListInfo::empty() -{ - return next == this; -} - -TaskList* -TaskListInfo::getNext(TaskList* q) -{ - if (q->next==this) return NULL; - return q->next; -} - -int -TaskListInfo::length() -{ - int i = 1; - if (empty()) return 0; - TaskList* e = first; - while((e = e->next) != this ) i++; - return i; -} - - - - -/* end */ - - diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskListInfo.h --- a/TaskManager/kernel/ppe/TaskListInfo.h Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#ifndef INCLUDED_TASK_LIST_INFO -#define INCLUDED_TASK_LIST_INFO - -#include "types.h" -#include "TaskList.h" - -class TaskListInfo : public TaskList { -public: - /* constructor */ - TaskListInfo(); - - BASE_NEW_DELETE(TaskListInfo); - - /* functions */ - TaskListPtr create(); - - void free_(TaskListPtr queue); - void freeAll(); - - void addFirst(TaskList* e); - void addLast(TaskList* e); - TaskList* getFirst(); - TaskList* getLast(); - int remove(TaskList* e); - TaskList* poll(); - void moveToFirst(TaskList* e); // or use(); - TaskList* get(int index); - TaskList* find(TaskList *task); - int empty(); - void freePool() ; - - // Iterator - TaskList* getNext(TaskList* q) ; - int length(); - static TaskListInfo taskListPool; - -private: - /* variables */ - - TaskList* first; - TaskList* last; - - /* functions */ - int extend_pool(int num); - void destroy(); -}; - -typedef TaskListInfo *TaskListInfoPtr; - -#endif - diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskManagerImpl.cc --- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Wed Aug 04 16:46:25 2010 +0900 @@ -8,6 +8,11 @@ #include "SysFunc.h" #include +// singleton +QueueInfo *taskQueuePool = new QueueInfo() ; +QueueInfo *htaskPool = new QueueInfo() ; +QueueInfo *taskListPool = new QueueInfo() ; + static HTaskPtr systask_start; static HTaskPtr systask_finish; @@ -20,13 +25,13 @@ TaskManagerImpl::TaskManagerImpl(int num) : machineNum(num){ // 実行可能なHTaskのリスト - activeTaskQueue = new HTaskInfo(); + activeTaskQueue = new QueueInfo(htaskPool); // wait_forで止まっているHTaskのリスト。必要ないが、Dead lock detection に使う - waitTaskQueue = new HTaskInfo(); - // HTask の factory. HTaskInfo ならなんでもいい。 - htaskImpl = waitTaskQueue ; // any HTaskInfo - // Task の dependency を表現する double linked list. HTaskInfo とは別に必要。 - taskQueueImpl = new TaskQueueInfo(); + waitTaskQueue = new QueueInfo(htaskPool); + // HTask の factory. QueueInfo ならなんでもいい。 + htaskImpl = waitTaskQueue ; // any QueueInfo + // Task の dependency を表現する double linked list. QueueInfo とは別に必要。 + taskQueueImpl = new QueueInfo(taskQueuePool); } /** @@ -55,7 +60,8 @@ TaskManagerImpl::create_task(int cmd,memaddr rbuf, long r_size, memaddr wbuf, long w_size, void *from) { HTaskPtr new_task; - new_task = htaskImpl->create(cmd, rbuf, r_size, wbuf, w_size); + new_task = htaskImpl->create(); + new_task->init(cmd, rbuf, r_size, wbuf, w_size); new_task->post_func = noaction; new_task->mimpl = this; new_task->from = (memaddr)from; @@ -90,7 +96,7 @@ HTaskPtr new_task; // for compatibility - new_task = htaskImpl->create(TaskArray1); + new_task = htaskImpl->create(); new_task->init(TaskArray1); new_task->post_func = noaction; new_task->mimpl = this; new_task->create_task_array(cmd,1,8,8,8); @@ -123,8 +129,8 @@ TaskQueuePtr m, s; if (!master->self) return; - m = taskQueueImpl->create(master); - s = taskQueueImpl->create(slave); + m = taskQueueImpl->create(); m->init(master); + s = taskQueueImpl->create(); s->init(slave); master->wait_me->addLast(s); slave->wait_i->addLast(m); @@ -175,7 +181,7 @@ #if 0 static void -check_wait(TaskManagerImpl *tm, TaskQueueInfo *wait_i) { +check_wait(TaskManagerImpl *tm, QueueInfo *wait_i) { for(TaskQueue *t = wait_i->getFirst(); t; t = wait_i->getNext(t)) { if (!tm->waitTaskQueue->find(t->task)) { printf("stray waiting task%d %lx\n",t->task->command, (long)t->task); @@ -194,11 +200,11 @@ * @param [task] 終了したタスク */ void -TaskManagerImpl::check_task_finish(HTaskPtr me, HTaskInfo *wait_queue) +TaskManagerImpl::check_task_finish(HTaskPtr me, QueueInfo *wait_queue) { while(TaskQueue *p = me->wait_me->poll()) { HTaskPtr you = p->task; - TaskQueueInfo *wait_i = you->wait_i; + QueueInfo *wait_i = you->wait_i; // 相手の wait queue から自分(を指しているTaskQueue)を削除 wait_i->remove(p->waiter); // queue を free する @@ -229,7 +235,7 @@ * @param [task] 終了したタスク */ void -TaskManagerImpl::check_task_list_finish(SchedTask *s, TaskListPtr list, HTaskInfo *wait_queue) +TaskManagerImpl::check_task_list_finish(SchedTask *s, TaskListPtr list, QueueInfo *wait_queue) { for(int i = 0;ilength;i++) { SimpleTaskPtr task = &list->tasks[i]; @@ -264,7 +270,7 @@ TaskList は自動的に延長される */ void -TaskManagerImpl::set_taskList(HTaskPtr htask, TaskListInfoPtr taskList) { +TaskManagerImpl::set_taskList(HTaskPtr htask, QueueInfo * taskList) { TaskListPtr list ; if ( taskList->empty() ) { list = taskList->create(); diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskManagerImpl.h --- a/TaskManager/kernel/ppe/TaskManagerImpl.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Wed Aug 04 16:46:25 2010 +0900 @@ -3,23 +3,28 @@ #include "MailManager.h" #include "ListData.h" -#include "TaskListInfo.h" -#include "TaskQueueInfo.h" -#include "HTaskInfo.h" +#include "QueueInfo.h" +#include "TaskQueue.h" +#include "HTask.h" #include "Scheduler.h" class MemList; +extern QueueInfo *taskQueuePool ; +extern QueueInfo *htaskPool ; +extern QueueInfo *taskListPool; + + class TaskManagerImpl { public: /* variables */ int machineNum; - HTaskInfo *activeTaskQueue; - HTaskInfo *waitTaskQueue; + QueueInfo *activeTaskQueue; + QueueInfo *waitTaskQueue; - TaskQueueInfo *taskQueueImpl; - HTaskInfo *htaskImpl; + QueueInfo *taskQueueImpl; + QueueInfo *htaskImpl; SchedTask *schedTaskManager; Scheduler *scheduler; @@ -40,8 +45,8 @@ virtual void append_waitTask(HTaskPtr); virtual void polling() = 0; - void check_task_finish(HTaskPtr task, HTaskInfo *wait_queue); - void check_task_list_finish(SchedTask *s, TaskListPtr list, HTaskInfo *wait_queue); + void check_task_finish(HTaskPtr task, QueueInfo *wait_queue); + void check_task_list_finish(SchedTask *s, TaskListPtr list, QueueInfo *wait_queue); void systask_init(); @@ -52,7 +57,7 @@ virtual void set_task_depend(HTaskPtr master, HTaskPtr slave); virtual void spawn_task(HTaskPtr); virtual void set_task_cpu(HTaskPtr, CPU_TYPE); - void set_taskList(HTaskPtr htask, TaskListInfoPtr taskList) ; + void set_taskList(HTaskPtr htask, QueueInfo * taskList) ; void free_htask(HTaskPtr htask) { #if !defined(__SPU__) diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskQueue.h --- a/TaskManager/kernel/ppe/TaskQueue.h Tue Aug 03 15:32:49 2010 +0900 +++ b/TaskManager/kernel/ppe/TaskQueue.h Wed Aug 04 16:46:25 2010 +0900 @@ -22,6 +22,13 @@ TaskQueue *next; TaskQueue *prev; + void init() { } + + TaskQueue *init(HTask *task) { + this->task = task; + return this; + } + } ; typedef TaskQueue* TaskQueuePtr; diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskQueueInfo.cc --- a/TaskManager/kernel/ppe/TaskQueueInfo.cc Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -#include -#include -#include "TaskQueueInfo.h" - -// Singleton TaskQueue Pool -TaskQueueInfo TaskQueueInfo::taskQueuePool; - -TaskQueueInfo::TaskQueueInfo() { - // 最初の一つは自分 - first = last = this; - next = prev = this; - waiter = NULL; -} - -void -TaskQueueInfo::freePool() { - for(TaskQueuePtr p = taskQueuePool.waiter; p; ) { - TaskQueuePtr next = p->waiter; - p->waiter = NULL; - free(p); - p = next; - } -} - -int -TaskQueueInfo::extend_pool(int num) -{ - TaskQueuePtr q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(num+1)); - - // First Queue is previous pool - q->waiter = waiter; waiter = q; - q++; - - /* Connect all free queue in the pool */ - TaskQueuePtr p = q; - for (; num-- > 0; p++) { - p->task = NULL; - p->waiter = NULL; - taskQueuePool.addLast(p); - } - - return 0; -} - -TaskQueuePtr -TaskQueueInfo::create(HTask *task) -{ - TaskQueuePtr q = taskQueuePool.poll(); - if (! q) { - taskQueuePool.extend_pool(64); - q = taskQueuePool.poll(); - } - q->next = q->prev = NULL; - q->waiter = NULL; - q->task = task; - - return q; -} - - -void -TaskQueueInfo::free_(TaskQueuePtr q) -{ - q->waiter = NULL; - q->task = NULL; - taskQueuePool.addLast(q); -} - - -/*! - TaskQueueInfo は空にならない。最低1個は要素が入っていて - 1個目は特別扱いする。getFirst すると first->next を返す - */ - -/*! - 最初の1個は特別扱いなので、それの後に追加していく - */ -void -TaskQueueInfo::addFirst(TaskQueue* e) -{ - e->prev = first; - e->next = first->next; - first->next->prev = e; - first->next = e; -} - -void -TaskQueueInfo::addLast(TaskQueue* e) -{ - e->next = first; - e->prev = last; - last->next = e; - last = e; -} - -TaskQueue* -TaskQueueInfo::getFirst() -{ - if (empty()) return NULL; - return first->next; -} - -TaskQueue* -TaskQueueInfo::getLast() -{ - if (empty()) return NULL; - return last; -} - -int -TaskQueueInfo::remove(TaskQueue* e) -{ - e->prev->next = e->next; - e->next->prev = e->prev; - - if (first->next == e) { - first->next = e->next; - } - if (last == e) { - last = e->prev; - } - - e->prev = NULL; - e->next = NULL; - - return 1; -} - -/*! - リストの先頭を取得および削除する。リストが空の場合は NULL を返す。 - */ - -TaskQueue* -TaskQueueInfo::poll() -{ - TaskQueue* e = first->next; - if (e == this) { - return NULL; - } - remove(e); - return e; -} - -void -TaskQueueInfo::moveToFirst(TaskQueue* e) -{ - remove(e); - addFirst(e); -} - -/*! - リスト内の指定された位置にある要素を返す。 - 要素数を超えた位置を指定した場合 NULL を返す。 - */ - -TaskQueue* -TaskQueueInfo::get(int index) -{ - TaskQueue* e = first->next; - for (int i = 0; i < index; i++) { - if (e == this) return NULL; - e = e->next; - } - return e; -} - -TaskQueue* -TaskQueueInfo::find(HTask* task) -{ - TaskQueue* e = first->next; - for(;;) { - if (e == this) return NULL; - if (e->task == task) return e; - e = e->next; - } - return e; -} - -int -TaskQueueInfo::empty() -{ - return next == this; -} - -TaskQueue* -TaskQueueInfo::getNext(TaskQueue* q) -{ - if (q->next==this) return NULL; - return q->next; -} - - - -/* end */ diff -r 6d3c954e510a -r 9989dd7b9ac2 TaskManager/kernel/ppe/TaskQueueInfo.h --- a/TaskManager/kernel/ppe/TaskQueueInfo.h Tue Aug 03 15:32:49 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#ifndef INCLUDED_TASK_QUEUE_INFO -#define INCLUDED_TASK_QUEUE_INFO - -#include "TaskQueue.h" - -class HTask; - -class TaskQueueInfo : public TaskQueue { - - -public: - /* constructor */ - TaskQueueInfo(); - - BASE_NEW_DELETE(TaskQueueInfo); - - /* functions */ - TaskQueuePtr create(HTask *task); - void free_(TaskQueuePtr queue); - - void addFirst(TaskQueue* e); - void addLast(TaskQueue* e); - TaskQueue* getFirst(); - TaskQueue* getLast(); - int remove(TaskQueue* e); - TaskQueue* poll(); - void moveToFirst(TaskQueue* e); // or use(); - TaskQueue* get(int index); - TaskQueue* find(HTask *task); - int empty(); - void freePool() ; - - // Iterator - TaskQueue* getNext(TaskQueue* q) ; - int hasNext(TaskQueue* q); - -private: - /* variables */ - - static TaskQueueInfo taskQueuePool; - TaskQueue* first; - TaskQueue* last; - - /* functions */ - int extend_pool(int num); - void destroy(); -} ; - -#endif