changeset 489:a2bf77602343

merge
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Tue, 06 Oct 2009 14:22:41 +0900
parents 63741e2dc6cb (current diff) bfbad00ed9be (diff)
children 892eff521871
files TaskManager/Cell/spe/Task.cc TaskManager/Cell/spe/TaskList.cc TaskManager/Cell/spe/TaskQueue.cc TaskManager/kernel/ppe/SymTable.cc TaskManager/kernel/ppe/SymTable.h
diffstat 27 files changed, 455 insertions(+), 553 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/CellHTaskInfo.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/Cell/CellHTaskInfo.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -20,10 +20,14 @@
 	q->next = q + 1;
 	posix_memalign((void**)&q->inData, DEFAULT_ALIGNMENT, sizeof(ListData));
 	posix_memalign((void**)&q->outData, DEFAULT_ALIGNMENT, sizeof(ListData));
+        q->wait_me = new TaskQueueInfo();
+        q->wait_i = new TaskQueueInfo();
     }
     q->next = freeHTask;
     posix_memalign((void**)&q->inData, DEFAULT_ALIGNMENT, sizeof(ListData));
     posix_memalign((void**)&q->outData, DEFAULT_ALIGNMENT, sizeof(ListData));
+    q->wait_me = new TaskQueueInfo();
+    q->wait_i = new TaskQueueInfo();
 
     freeHTask = htaskPool + 1;
 
--- a/TaskManager/Cell/CellTaskManagerImpl.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/Cell/CellTaskManagerImpl.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -33,6 +33,8 @@
     taskListImpl = new CellTaskListInfo;
     taskListImpl->init(machineNum*2);
 
+    activeTaskQueue = new TaskQueueInfo();
+
     htaskImpl = new CellHTaskInfo;
     htaskImpl->init(TASK_MAX_SIZE*2);
 
@@ -53,19 +55,18 @@
     } 
     // PPE 側の管理をする Manager
     ppeManager = new FifoTaskManagerImpl(machineNum);
+    // 大半のTaskQueueInfoは、共有される
     ppeManager->init(new PpeScheduler, this);
 }
 
 void
 CellTaskManagerImpl::append_activeTask(HTaskPtr task)
 {
-    TaskQueuePtr q;
-
-    q = taskQueueImpl->create(task);
     if (task->cpu_type == CPU_PPE) {
         ppeManager->append_activeTask(task);
     } else {
-        activeTaskQueue = TaskQueue::append(activeTaskQueue, q);
+	TaskQueuePtr q = taskQueueImpl->create(task);
+        activeTaskQueue->addLast(q);
     }
 }
 
@@ -86,21 +87,18 @@
 {
     // ここ...直すかな
     TaskListPtr list;
-    TaskQueuePtr queue;
+    
     TaskQueuePtr d;
     HTaskPtr htask;
     TaskPtr task;
     int speid;
 
-    queue = activeTaskQueue;
-    if (queue == NULL) {
+    if (activeTaskQueue->empty()) {
 	return ;
     }
  
-    while (queue) {
+    while (TaskQueuePtr queue = activeTaskQueue->poll()) {
 	htask = (HTaskPtr)queue->task;
-	d = queue;
-	queue = queue->next;
 
 	if (htask->cpu_type == SPE_ANY) {
 	    speid = cur_anySpeid++;
@@ -138,13 +136,12 @@
 	task->outData  = htask->outData;
 	task->self     = (unsigned int)htask;
 #else
-	memcpy(task, htask, sizeof(Task));
+	memcpy(task, (Task*)htask, sizeof(Task));
 #endif
 
-	taskQueueImpl->free(d);
+	activeTaskQueue->free(queue);
     }
 
-    activeTaskQueue = NULL;
 }
 
 void
@@ -185,7 +182,7 @@
 CellTaskManagerImpl::mail_check(MailQueuePtr mail_list)
 {
     // PPE Scheduler からの mail check
-    ppeManager->mail_check(mail_list, &waitTaskQueue);
+    ppeManager->mail_check(mail_list, waitTaskQueue);
 
     do {
 	unsigned int data;
@@ -258,7 +255,7 @@
 	// であり、この場合もし SPE にタスクが残っていても
 	// メインループから抜けてプログラム終了となってしまうので
 	// ここでストップかけてます。
-    } while (!ppeManager->activeTaskQueue && waitTaskQueue);
+    } while (ppeManager->activeTaskQueue->empty() && !waitTaskQueue->empty());
 	
     return ppeManager->get_runTaskList();
 }
--- a/TaskManager/Cell/spe/Task.cc	Tue Oct 06 14:21:37 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-#include "Task.h"
-
-/**
- * タスクの入力データを追加する
- *
- * @param [addr] add input data
- * @param [size] size of data at [addr]
- *
- * @return if ([ret] == 0) ? success : failuer;
- */
-int
-Task::add_inData_t(unsigned int addr, int size)
-{
-    return add_data(this->inData, addr, size);
-}
-
-int
-Task::add_outData_t(unsigned int addr, int size)
-{
-    return add_data(this->outData, addr, size);
-}
-
-/**
- * エラーの時に -1 を返す、ってことするよりは
- * perror みたいにしたほうがわかりやすいかな。
- *
- * 現在は 3 個まで。
- * 本当は、3個以上にすると task->param[] には アドレスが入り
- * そのアドレスは メインメモリでアロケートされた int の集合。
- */
-int
-Task::add_param(int _param)
-{
-    if (param_size >= MAX_PARAMS) return -1;
-
-    this->param[param_size++] = _param;
-    return 0;
-}
-
-/*
- * エラーの時に -1 を返す、ってことするよりは
- * perror みたいにしたほうがわかりやすいかな。
- */
-int
-Task::add_data(ListDataPtr list, uint32 addr, int size)
-{
-    if (list->length >= MAX_LIST_DMA_SIZE) return -1;
-
-    list->bound[list->length] = list->size;
-
-    // size でも制限かけるべき?
-    list->size += size;
-
-    ListElementPtr elm = &list->element[list->length++];
-    elm->addr = addr;
-    elm->size = size;
-
-    return 0;
-}
--- a/TaskManager/Cell/spe/TaskList.cc	Tue Oct 06 14:21:37 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#include "TaskList.h"
-
-TaskListPtr
-TaskList::append(TaskListPtr list, TaskListPtr q)
-{
-    TaskListPtr p = list;
-
-    if (!p) {
-	return q;
-    } else {
-	while (p->next) p = p->next;
-	p->next = q;
-	return list;
-    }
-}
-
--- a/TaskManager/Cell/spe/TaskQueue.cc	Tue Oct 06 14:21:37 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#include "TaskQueue.h"
-
-TaskQueue::TaskQueue(TaskPtr q)
-{
-    task = q;
-    next = NULL;
-}
-
-TaskQueuePtr
-TaskQueue::append(TaskQueuePtr list, TaskQueuePtr q)
-{
-    TaskQueuePtr p = list;
-
-    if (!p) {
-	return q;
-    } else {
-	while(p->next) p = p->next;
-	p->next = q;
-	return list;
-    }
-}
--- a/TaskManager/ChangeLog	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/ChangeLog	Tue Oct 06 14:22:41 2009 +0900
@@ -1,3 +1,7 @@
+2009-10-05 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
+
+    TaskQueue のfree list の管理はシステムで一つであるべき。
+
 2009-10-02 Shinji KONO <kono@ie.u-ryukyu.ac.jp>
 
     DrawSpan で、~DrawSpan() で、allocate したデータを DMA_WAIT
--- a/TaskManager/Fifo/FifoTaskManagerImpl.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -37,8 +37,6 @@
     taskQueueImpl = new TaskQueueInfo;
     htaskImpl     = new HTaskInfo;
 
-    machineNum = machineNum*2; // What!?
-
     taskQueueImpl->init(TASK_MAX_SIZE*4);
     htaskImpl->init(TASK_MAX_SIZE*2);
 
@@ -66,9 +64,16 @@
     taskListImpl  = tm-> taskListImpl  ;
     taskQueueImpl = tm-> taskQueueImpl ;
     htaskImpl     = tm-> htaskImpl     ;
+    waitTaskQueue     = NULL;   // mail_check で外から設定される
+//    waitTaskQueue     = tm->waitTaskQueue; 
+//    activeTaskQueue     = NULL; // CellTaskManagerImple 側を使う
+
+    // waitTaskQueue     = tm->waitTaskQueue; 
+    // activeQueue は?
 
     mainTaskList = taskListImpl->create();
 
+
 }
 
 /**
@@ -83,13 +88,10 @@
 FifoTaskManagerImpl::get_runTaskList()
 {
     TaskListPtr list, list_top;
-    TaskQueuePtr queue;
-    TaskQueuePtr d;
     HTaskPtr htask; // HTask (PPE にある)
     TaskPtr task; // Task (SPE に送る Task)
 
-    queue = activeTaskQueue;
-    if (queue == NULL) {
+    if (activeTaskQueue->empty()) {
         return NULL;
     }
 
@@ -100,14 +102,12 @@
     list_top = taskListImpl->clear_taskList(list_top);
     list = list_top;
 
-    while (queue) {
+    while (TaskQueuePtr queue = activeTaskQueue->poll()) {
         htask = (HTaskPtr)queue->task;
-        d = queue;
-        queue = queue->next;
 
         task = &list->tasks[list->length++];
 
-        memcpy(task, htask, sizeof(Task));
+        memcpy(task, (Task*)htask, sizeof(Task));
 
         if (list->length >= TASK_MAX_SIZE) {
             TaskListPtr newList = taskListImpl->create();
@@ -115,10 +115,9 @@
             list = newList;
         }
 
-        taskQueueImpl->free(d);
+        activeTaskQueue->free(queue);
     }
 
-    activeTaskQueue = NULL;
     mainTaskList = list_top;
 
     return list_top;
@@ -187,6 +186,13 @@
  *         NULL なら全てのタスクが実行終了したということ
  */
 void
+FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueueInfo *waitQueue)
+{
+    waitTaskQueue = waitQueue;
+    mail_check(mail_list);
+}
+
+void
 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list)
 {
     MailQueuePtr q = mail_list;
@@ -219,13 +225,6 @@
     }
 }
 
-void
-FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueuePtr *wait)
-{
-    waitTaskQueue = *wait;
-    mail_check(mail_list);
-}
-
 void*
 FifoTaskManagerImpl::allocate(int size)
 {
--- a/TaskManager/Fifo/FifoTaskManagerImpl.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.h	Tue Oct 06 14:22:41 2009 +0900
@@ -13,7 +13,7 @@
 
     /* variables */
     int machineNum;
-    TaskListPtr mainTaskList;
+    TaskListPtr mainTaskList;  // activeTask であるべきなんじゃないの?
 
     MailManager *mailManager;
     MainScheduler *scheduler;
@@ -24,7 +24,7 @@
     void init(MainScheduler*, TaskManagerImpl*);
     void run(void);
     void mail_check(MailQueuePtr mail_list);
-    void mail_check(MailQueuePtr mail_list, TaskQueuePtr *waitQueue);
+    void mail_check(MailQueuePtr mail_list, TaskQueueInfo *waitQueue);
     TaskListPtr get_runTaskList(void);
     MailQueuePtr schedule(TaskListPtr);
 
--- a/TaskManager/Makefile.cell	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/Makefile.cell	Tue Oct 06 14:22:41 2009 +0900
@@ -19,15 +19,17 @@
 
 CELL_SPE_SRCS =  \
     $(CELL_SPE_DIR)/CellDmaManager.cc   \
+    $(CELL_SPE_DIR)/CellScheduler.cc    \
+    $(CELL_SPE_DIR)/main.cc
+
+CELL_SPE_TASK_SRCS =  \
     $(CELL_SPE_DIR)/TaskList.cc \
-    $(CELL_SPE_DIR)/CellScheduler.cc    \
     $(CELL_SPE_DIR)/TaskQueue.cc \
-    $(CELL_SPE_DIR)/Task.cc            \
-    $(CELL_SPE_DIR)/main.cc
+    $(CELL_SPE_DIR)/Task.cc           
 
 # $(wildcard $(CELL_SPE_DIR)/*.cc)
 
-CELL_SPE_OBJS = $(CELL_SPE_SRCS:.cc=.o) $(CELL_SPE_SCHEDULE_OBJ)
+CELL_SPE_OBJS = $(CELL_SPE_SRCS:.cc=.o) $(CELL_SPE_SCHEDULE_OBJ) $(CELL_SPE_TASK_SRCS:.cc=.o)
 
 SPUCC = spu-g++
 
@@ -53,6 +55,8 @@
 $(CELL_SPE_SCHEDULE_SRC): kernel/schedule/*.cc
 	cp kernel/schedule/*.cc $(CELL_SPE_DIR)/
 	cp kernel/memory/*.cc $(CELL_SPE_DIR)/
+	cp kernel/ppe/{TaskList.cc,TaskQueue.cc,Task.cc} $(CELL_SPE_DIR)/
+
 $(CELL_SPE_OBJS): %.o : %.cc
 	$(SPUCC) $(CFLAGS) $(SPE_CFLAGS) $(INCLUDE) -c $< -o $@
 
@@ -61,7 +65,7 @@
 	rm -f $(SPETARGET)
 
 cellclean:
-	rm -f $(CELL_SPE_OBJS) $(CELL_SPE_SCHEDULE_SRC)
+	rm -f $(CELL_SPE_OBJS) $(CELL_SPE_SCHEDULE_SRC) $(CELL_SPE_TASK_SRCS)
 	(cd $(CELL_SPE_DIR); rm -f *~ \#*)
 
 
--- a/TaskManager/kernel/ppe/HTask.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/HTask.h	Tue Oct 06 14:22:41 2009 +0900
@@ -6,6 +6,7 @@
 #include "Task.h"
 #include "TaskQueueInfo.h"
 
+class TaskQueueInfo;
 class TaskManagerImpl;
 
 /*!
@@ -23,12 +24,12 @@
 public:
     BASE_NEW_DELETE(HTask);
 
-    TaskQueuePtr wait_me;  // List of task waiting for me
-    TaskQueuePtr wait_i;   // List of task for which I am waiting
+    TaskQueueInfo *wait_me;  // List of task waiting for me
+    TaskQueueInfo *wait_i;   // List of task for which I am waiting
     void (*post_func)(void *arg);
     void *post_arg;
     CPU_TYPE cpu_type;
-    HTask *next;
+    HTask *next;             // free list 用
     TaskManagerImpl *mimpl;
 
     void spawn(void);
--- a/TaskManager/kernel/ppe/HTaskInfo.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/HTaskInfo.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -37,12 +37,16 @@
     /* Connect all free queue in the pool */
     for (q = htaskPool + 1; --num > 0; q++) {
 	q->next = q + 1;
+	q->wait_me = new TaskQueueInfo();
+	q->wait_i = new TaskQueueInfo();
 	q->inData = (ListDataPtr)malloc(sizeof(ListData));
 	q->outData = (ListDataPtr)malloc(sizeof(ListData));
     }
     q->next = freeHTask;
     q->inData = (ListDataPtr)malloc(sizeof(ListData));
     q->outData = (ListDataPtr)malloc(sizeof(ListData));
+    q->wait_me = new TaskQueueInfo();
+    q->wait_i = new TaskQueueInfo();
 
     freeHTask = htaskPool + 1;
 
@@ -72,8 +76,6 @@
     q->self = (unsigned int)q;
     q->param_size = 0;
 
-    q->wait_me  = NULL;
-    q->wait_i   = NULL;
     q->post_func = NULL;
     q->mimpl     = NULL;
     q->cpu_type  = CPU_PPE;
--- a/TaskManager/kernel/ppe/SymTable.cc	Tue Oct 06 14:21:37 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-#include <string.h>
-#include "SymTable.h"
-
-SymTable::~SymTable(void)
-{
-    SymTbPtr tb;
-
-    for (int i = 0; i < symtb_index; i++) {
-	tb = &symtb[i];
-	delete [] tb->sym;
-    }
-
-    delete [] symtb;
-}
-
-void
-SymTable::init(void)
-{
-    symtb = new SymTb[SYM_MAX_SIZE];
-    symtb_index = 0;
-}
-
-void
-SymTable::set_symbol(const char *sym, FuncObject addr)
-{
-    SymTbPtr tb = &symtb[symtb_index++];
-
-    tb->sym = new char[strlen(sym)+1];
-    memcpy(tb->sym, sym, strlen(sym)+1);
-    tb->address = addr;
-}
-
-void
-SymTable::set_func(int id, FuncObject addr)
-{
-     SymTbPtr tb = &symtb[id];
-
-     tb->address = addr;
-}
-
-SymTable::FuncObject
-SymTable::get_address(int fd)
-{
-    if (fd >= symtb_index) {
-	// Fix me
-	// error process
-    }
-
-    return symtb[fd].address;
-}
-
-
-int
-SymTable::get_fd(const char *sym)
-{
-    SymTbPtr tb;
-
-    for (int i = 0; i < SYM_MAX_SIZE; i++) {
-	tb = &symtb[i];
-	if (strcmp(tb->sym, sym) == 0) {
-	    return i;
-	}
-    }
-
-    return -1;
-}
--- a/TaskManager/kernel/ppe/SymTable.h	Tue Oct 06 14:21:37 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#ifndef INCLUDED_SYMTABLE
-#define INCLUDED_SYMTABLE
-
-#define SYM_MAX_SIZE 64
-
-class SymTable {
-public:
-    ~SymTable(void);
-
-    typedef int (*FuncObject)(void *, void*);
-
-    typedef struct sym_table {
-	 char *sym;
-	 FuncObject address;
-    } SymTb, *SymTbPtr;
-
-    SymTbPtr symtb;
-    int symtb_index;
-
-    void init(void);
-    void set_symbol(const char *sym, FuncObject addr);
-    void set_func(int id, FuncObject addr);
-    int get_fd(const char *sym);
-    FuncObject get_address(int fd);
-};
-
-#endif
--- a/TaskManager/kernel/ppe/Task.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/Task.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -31,6 +31,10 @@
 /**
  * エラーの時に -1 を返す、ってことするよりは
  * perror みたいにしたほうがわかりやすいかな。
+ *
+ * 現在は 3 個まで。
+ * 本当は、3個以上にすると task->param[] には アドレスが入り
+ * そのアドレスは メインメモリでアロケートされた int の集合。
  */
 int
 Task::add_param(int _param)
--- a/TaskManager/kernel/ppe/TaskManager.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskManager.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -90,3 +90,5 @@
 TaskManager::get_scheduler() {
     return m_impl->get_scheduler();
 }
+
+/* end */
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -13,7 +13,11 @@
 }
 
 TaskManagerImpl::TaskManagerImpl(int num)
-    : machineNum(num), activeTaskQueue(NULL), waitTaskQueue(NULL) {}
+    : machineNum(num) {
+    activeTaskQueue = new TaskQueueInfo();
+    waitTaskQueue = new TaskQueueInfo();
+    taskQueueImpl = new TaskQueueInfo();
+}
 
 /**
  * 一番最初に PPE で実行される systask_start
@@ -62,8 +66,9 @@
     m = taskQueueImpl->create(master);
     s = taskQueueImpl->create(slave);
 
-    master->wait_me = TaskQueue::append(master->wait_me, s);
-    slave->wait_i   = TaskQueue::append(slave->wait_i, m);
+    master->wait_me->addLast(s);
+    slave->wait_i->addLast(m);
+    s->waiter = m;
 }
 
 /**
@@ -76,7 +81,7 @@
 {
     // waiter // master
     // waitee // slave
-    if (task->wait_i == NULL) {
+    if (task->wait_i->empty()) {
         append_activeTask(task);
     } else {
         append_waitTask(task);
@@ -91,10 +96,8 @@
 void
 TaskManagerImpl::append_activeTask(HTaskPtr task)
 {
-    TaskQueuePtr q;
-
-    q = taskQueueImpl->create(task);
-    activeTaskQueue = TaskQueue::append(activeTaskQueue, q);
+    TaskQueuePtr q = taskQueueImpl->create(task);
+    activeTaskQueue->addLast(q);
 }
 
 /**
@@ -112,46 +115,33 @@
 /**
  * 終了したタスクから依存の処理とか
  * post_func() はこのタスクが終了したら実行する関数。
- * 今のところ使ってないっす
  *
  * @param [task] 終了したタスク
  */
 void
 TaskManagerImpl::check_task_finish(HTaskPtr task)
 {
-    notify_wait_taskQueue(task, task->wait_me);
+    while(TaskQueue *p = task->wait_me->poll()) {
+	HTaskPtr htask = (HTaskPtr)p->task;
+	TaskQueueInfo *wait_i = htask->wait_i;
+	// 相手の wait queue から自分(を指しているTaskQueue)を削除
+	wait_i->remove(p->waiter);
+	// queue を free する
+	wait_i->free(p->waiter);
+
+	wait_i->free(p);
+    }
+
     task->post_func(task->post_arg);
     htaskImpl->free(task);
 }
 
-/**
- * 終了したタスク [depend] を待っている TaskList に
- * 終わった事を知らせる(削除する
- */
-void
-TaskManagerImpl::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list)
-{
-    TaskQueuePtr p;
-    HTaskPtr task;
-
-    p = list; // wait task list
-
-    while (p) {
-        task = (HTaskPtr)p->task;
-        task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend);
-        p = p->next;
-    }
-
-    remove_taskQueue_all(list);
-}
 
 void
 TaskManagerImpl::append_waitTask(HTaskPtr task)
 {
-    TaskQueuePtr q;
-
-    q = taskQueueImpl->create(task);
-    waitTaskQueue = TaskQueue::append(waitTaskQueue, q);
+    TaskQueuePtr q = taskQueueImpl->create(task);
+    waitTaskQueue ->addLast(q);
 }
 
 /**
@@ -161,87 +151,12 @@
 void
 TaskManagerImpl::wakeup_waitTask(void)
 {
-    TaskQueuePtr p, tmp;
-
-    p = waitTaskQueue;
-    while (p) {
+    while (TaskQueuePtr p = waitTaskQueue->poll()) {
         HTaskPtr task = (HTaskPtr)p->task;
-        tmp = p;
-        p = p->next;
-        if (task->wait_i == NULL) {
-            append_activeTask(task);
-            waitTaskQueue = remove_taskQueue(waitTaskQueue, tmp);
+        if (task->wait_i->empty()) {
+	    activeTaskQueue->addLast(p);
         }
     }
 }
 
-void
-TaskManagerImpl::remove_taskQueue_all(TaskQueuePtr list)
-{
-    TaskQueuePtr p = list;
-    TaskQueuePtr p1;
-
-    while (p != NULL) {
-        p1 = p->next;
-        taskQueueImpl->free(p);
-        p = p1;
-    }
-}
-
-/**
- * [list] が持つ queue->task の中に [task] と同じ奴があれば
- * 削除する。まあ remove_taskQueue() の HTask で比較するverです。
- * こういうのはオーバーロードでやるもんなのかな?
- */
-TaskQueuePtr
-TaskManagerImpl::remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task)
-{
-    TaskQueuePtr p = list;
-    TaskQueuePtr p1;
-
-    if (p == NULL) return p;
-
-    if (p->task == task) {
-        list = list->next;
-        taskQueueImpl->free(p);
-    } else {
-        p1 = p->next;
-        while (p1 && p1->task && p1->task != task) {
-            p1 = p1->next;
-            p = p->next;
-        }
-        if (p1) {
-            p->next = p1->next;
-            taskQueueImpl->free(p1);
-        }
-    }
-
-    return list;
-}
-
-TaskQueuePtr
-TaskManagerImpl::remove_taskQueue(TaskQueuePtr list, TaskQueuePtr q)
-{
-    TaskQueuePtr p = list;
-    TaskQueuePtr p1;
-
-    if (!p) return p;
-
-    if (p == q) {
-        list = list->next;
-        taskQueueImpl->free(p);
-    } else {
-        p1 = p->next;
-        while (p1 && p1 != q) {
-            p1 = p1->next;
-            p = p->next;
-        }
-        if (p1) {
-            p->next = p1->next;
-            taskQueueImpl->free(p1);
-        }
-    }
-
-    return list;
-}
-
+/* end */
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskManagerImpl.h	Tue Oct 06 14:22:41 2009 +0900
@@ -11,35 +11,33 @@
 
 class TaskManagerImpl {
 public:
-    /* constructor */
-    TaskManagerImpl(int num = 1);
-    virtual ~TaskManagerImpl(void) {}
 
     /* variables */
     int machineNum;
-    TaskQueuePtr activeTaskQueue;
-    TaskQueuePtr waitTaskQueue;
+    TaskQueueInfo *activeTaskQueue;
+    TaskQueueInfo *waitTaskQueue;
 
     /* variables */
     TaskListInfo *taskListImpl;
     TaskQueueInfo *taskQueueImpl;
     HTaskInfo *htaskImpl;
 
+    /* constructor */
+    TaskManagerImpl(int num = 1) ;
+
+    virtual ~TaskManagerImpl() { }
+
     /* functions */
     // system
-    virtual void init(void) = 0;
-    virtual void run(void) = 0;
+    virtual void init() = 0;
+    virtual void run() = 0;
     virtual void append_activeTask(HTaskPtr);
     virtual void append_waitTask(HTaskPtr);
 
     void check_task_finish(HTaskPtr task);
-    void notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list);
-    TaskQueuePtr remove_taskQueue(TaskQueuePtr list, TaskQueuePtr task);
-    TaskQueuePtr remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task);
-    void remove_taskQueue_all(TaskQueuePtr list);
-    void wakeup_waitTask(void);
+    void wakeup_waitTask();
 
-    void systask_init(void);
+    void systask_init();
 
     // user
     HTaskPtr create_task(int cmd);
--- a/TaskManager/kernel/ppe/TaskQueue.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskQueue.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -1,21 +1,29 @@
 #include "TaskQueue.h"
 
-TaskQueue::TaskQueue(TaskPtr q)
+TaskQueue::TaskQueue(Task *q)
 {
     task = q;
     next = NULL;
+    prev = NULL;
+    waiter = NULL;
 }
 
+/*
+ *  こんなものは使いたくないが、renew task/task group が
+ *  が、あまりに ad-hoc で直し切れないので、とりあえず、
+ *  存続。TaskQueueInfo は SchedTask で使うにはでかすぎる。
+ */
 TaskQueuePtr
 TaskQueue::append(TaskQueuePtr list, TaskQueuePtr q)
 {
     TaskQueuePtr p = list;
 
     if (!p) {
-	return q;
+       return q;
     } else {
-	while(p->next) p = p->next;
-	p->next = q;
-	return list;
+       while(p->next) p = p->next;
+       p->next = q;
+       return list;
     }
 }
+
--- a/TaskManager/kernel/ppe/TaskQueue.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskQueue.h	Tue Oct 06 14:22:41 2009 +0900
@@ -2,20 +2,23 @@
 #define INCLUDED_TASK_QUEUE
 
 #include "base.h"
-#include "Task.h"
 
-#include <stdio.h>
+class Task;
 
 class TaskQueue {
 public:
-    TaskQueue(TaskPtr q = NULL);
+    TaskQueue(Task *q = NULL);
 
     BASE_NEW_DELETE(TaskQueue);
 
-    TaskPtr task;
-    class TaskQueue *next;
+    Task *task;
+    TaskQueue *waiter;
 
     static TaskQueue* append(TaskQueue* list, TaskQueue* q);
+
+    TaskQueue *next;
+    TaskQueue *prev;
+
 };
 
 typedef TaskQueue* TaskQueuePtr;
--- a/TaskManager/kernel/ppe/TaskQueueInfo.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskQueueInfo.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -2,8 +2,10 @@
 #include <stdlib.h>
 #include "TaskQueueInfo.h"
 
-TaskQueueInfo::TaskQueueInfo(void)
-    :taskQueuePool(NULL), freeTaskQueue(NULL) {}
+TaskQueueInfo::TaskQueueInfo()
+    :taskQueuePool(NULL), freeTaskQueue(NULL) {
+    init(32);
+}
 
 TaskQueueInfo::~TaskQueueInfo(void) { destroy(); }
 
@@ -11,8 +13,12 @@
 TaskQueueInfo::init(int num)
 {
     if (taskQueuePool == NULL) {
-	return extend_pool(num);
+	extend_pool(num);
     }
+    // 最初の一つは自分
+    first = last = this;
+    next = prev = this;
+    waiter = NULL;
     return 0;
 }
 
@@ -24,7 +30,7 @@
     q = (TaskQueuePtr)malloc(sizeof(TaskQueue)*(num+1));
 
     if (q == NULL) {
-	return -1;
+	return -1; // throw...
     }
     q->next = taskQueuePool;
     taskQueuePool = q;
@@ -45,13 +51,14 @@
     TaskQueuePtr q;
 
     if (freeTaskQueue == NULL) {
-	extend_pool(100);
+	extend_pool(64);
     }
     q = freeTaskQueue;
     freeTaskQueue = freeTaskQueue->next;
 
     q->task = task;
-    q->next = NULL;
+    q->next = q->prev = NULL;
+    q->waiter = NULL;
 
     return q;
 }
@@ -60,7 +67,9 @@
 void
 TaskQueueInfo::free(TaskQueuePtr q)
 {
+    // if (!q) return;
     q->next = freeTaskQueue;
+    q->prev = NULL;
     freeTaskQueue = q;
 }
 
@@ -86,3 +95,124 @@
 
 
 }
+
+
+/*!
+  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)
+{
+    // if (!e) return 0;
+
+    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(Task* 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;
+}
+
+
+/* end */
--- a/TaskManager/kernel/ppe/TaskQueueInfo.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/ppe/TaskQueueInfo.h	Tue Oct 06 14:22:41 2009 +0900
@@ -1,9 +1,10 @@
 #ifndef INCLUDED_TASK_QUEUE_INFO
 #define INCLUDED_TASK_QUEUE_INFO
 
+#include "Task.h"
 #include "TaskQueue.h"
 
-class TaskQueueInfo {
+class TaskQueueInfo : public TaskQueue {
 public:
     /* constructor */
     TaskQueueInfo();
@@ -11,13 +12,28 @@
 
     /* functions */
     int init(int num);
-    TaskQueuePtr create(TaskPtr task);
+    TaskQueuePtr create(Task *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(Task *task);
+    int empty();
+ 
 private:
     /* variables */
-    TaskQueuePtr taskQueuePool;
-    TaskQueuePtr freeTaskQueue;
+    TaskQueue* taskQueuePool;
+    TaskQueue* freeTaskQueue;
+
+    TaskQueue* first;
+    TaskQueue* last;
+
 
     /* functions */
     int extend_pool(int num);
--- a/TaskManager/kernel/schedule/SchedTask.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -39,17 +39,17 @@
 
 SchedTask::SchedTask()
 {
-    __list        = NULL;
-    __task        = NULL;
-    __inListData  = NULL;
-    __outListData = NULL;
-    __readbuf     = NULL;
-    __writebuf    = NULL;
-    __scheduler   = NULL;
-    __taskGroup   = NULL;
-    __renew_flag  = 0;
-    __cur_index   = 0;
-    __flag_renewTask = SCHED_TASK_NORMAL;
+    list        = NULL;
+    task        = NULL;
+    inListData  = NULL;
+    outListData = NULL;
+    readbuf     = NULL;
+    writebuf    = NULL;
+    scheduler   = NULL;
+    taskGroup   = NULL;
+    renew_flag  = 0;
+    cur_index   = 0;
+    flag_renewTask = SCHED_TASK_NORMAL;
     this->stdout_ = stdout;
     this->stderr_ = stderr;
     this->stdin_ = stdin;
@@ -65,25 +65,25 @@
 /**
  * dma_store の wait を行う
  * このタスクが RenewTask だった場合、
- * __inListData や __outListData は
+ * inListData や outListData は
  * Scheduler の持つ、使い回しの buffer ではなく
  * 新たに allocate されたものなので、ここで free する
  */
 SchedTask::~SchedTask()
 {
-    if (__flag_renewTask == SCHED_TASK_RENEW) {
-        free(__inListData);
-        free(__outListData);
+    if (flag_renewTask == SCHED_TASK_RENEW) {
+        free(inListData);
+        free(outListData);
 
         /**
-         * __list != NULL の場合、
-         * この Task が __list の最後の Task になるので (SchedTask::next 参照)
-         * このタイミングで __list を解放する
+         * list != NULL の場合、
+         * この Task が list の最後の Task になるので (SchedTask::next 参照)
+         * このタイミングで list を解放する
          *   (free に渡されるアドレスが正しいものとなる)。
          * それ以外の Task では当然解放しない。
-         *  __list == NULL なので、free に渡しても無問題
+         *  list == NULL なので、free に渡しても無問題
          */
-        free(__list);
+        free(list);
     }
 
 
@@ -93,9 +93,9 @@
  * このタスクを Renew Task とし、それに応じた関数をセットする
  */
 void
-SchedTask::__setRenew()
+SchedTask::setRenew()
 {
-    __flag_renewTask = SCHED_TASK_RENEW;
+    flag_renewTask = SCHED_TASK_RENEW;
 
     ex_init   = &SchedTask::ex_init_renew;
     ex_read   = &SchedTask::ex_read_renew;
@@ -105,17 +105,17 @@
 }
 
 void
-SchedTask::__init__(TaskListPtr _list, TaskPtr _task, int index,
+SchedTask::init(TaskListPtr _list, TaskPtr _task, int index,
                     ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc)
 {
-    __list        = _list;
-    __task        = _task;
-    __inListData  = rbuf;
-    __outListData = wbuf;
-    __scheduler   = sc;
-    __cur_index   = index;
+    list        = _list;
+    task        = _task;
+    inListData  = rbuf;
+    outListData = wbuf;
+    scheduler   = sc;
+    cur_index   = index;
 
-    __scheduler->mainMem_wait();
+    scheduler->mainMem_wait();
 
     (this->*ex_init)();
 }
@@ -126,17 +126,17 @@
 void
 SchedTask::ex_init_normal()
 {
-    __scheduler->dma_load(__inListData, (uint32)__task->inData,
+    scheduler->dma_load(inListData, (uint32)task->inData,
                           sizeof(ListData), DMA_READ_IN_LIST);
-    __scheduler->dma_load(__outListData, (uint32)__task->outData,
+    scheduler->dma_load(outListData, (uint32)task->outData,
                           sizeof(ListData), DMA_READ_OUT_LIST);
 #if defined(NO_PIPELINE)
-    __scheduler->dma_wait(DMA_READ_IN_LIST);
-    __scheduler->dma_wait(DMA_READ_OUT_LIST);
+    scheduler->dma_wait(DMA_READ_IN_LIST);
+    scheduler->dma_wait(DMA_READ_OUT_LIST);
 #endif
 
-    __taskGroup = new TaskGroup;
-    __taskGroup->command = __task->self;
+    taskGroup = new TaskGroup;
+    taskGroup->command = task->self;
 }
 
 /**
@@ -147,9 +147,9 @@
 void
 SchedTask::ex_init_renew()
 {
-    __inListData = __task->inData;
-    __outListData = __task->outData;
-    __taskGroup = (TaskGroupPtr)__task->self;
+    inListData = task->inData;
+    outListData = task->outData;
+    taskGroup = (TaskGroupPtr)task->self;
 }
 
 /**
@@ -167,21 +167,21 @@
     __debug("[SchedTask:%s]\n", __FUNCTION__);
 
 #if !defined(NO_PIPELINE)
-    __scheduler->dma_wait(DMA_READ_IN_LIST);
-    __scheduler->dma_wait(DMA_READ_OUT_LIST);
+    scheduler->dma_wait(DMA_READ_IN_LIST);
+    scheduler->dma_wait(DMA_READ_OUT_LIST);
 #endif
 
-    __writebuf = __scheduler->allocate(__outListData->size);
+    writebuf = scheduler->allocate(outListData->size);
 
     // 読むデータが一つもなければ無視
-    if (__inListData->length == 0) return;
+    if (inListData->length == 0) return;
 
     // load Input Data
-    __readbuf = __scheduler->allocate(__inListData->size);
-    __scheduler->dma_loadList(__inListData, __readbuf, DMA_READ);
+    readbuf = scheduler->allocate(inListData->size);
+    scheduler->dma_loadList(inListData, readbuf, DMA_READ);
 
 #if defined(NO_PIPELINE)
-    __scheduler->dma_wait(DMA_READ);
+    scheduler->dma_wait(DMA_READ);
 #endif
 
     (this->*ex_read)();
@@ -193,28 +193,28 @@
     __debug("[SchedTask:%s]\n", __FUNCTION__);
 
 #if !defined(NO_PIPELINE)
-    __scheduler->dma_wait(DMA_READ);
-    task_list[__task->command].wait(__scheduler,__task->command);
+    scheduler->dma_wait(DMA_READ);
+    task_list[task->command].wait(scheduler,task->command);
 #endif
 
-    task_list[__task->command].run(this, __readbuf, __writebuf);
+    task_list[task->command].run(this, readbuf, writebuf);
 
-    free(__readbuf);
+    free(readbuf);
 
-    if (__taskGroup->status() != 0) {
-        __task->self = __taskGroup->command;
-        delete __taskGroup;
-        __taskGroup = NULL;
+    if (taskGroup->status() != 0) {
+        task->self = taskGroup->command;
+        delete taskGroup;
+        taskGroup = NULL;
     }
 
 
     // 書き込む領域がなければ無視
-    if (__outListData->length > 0) {
-        __scheduler->dma_storeList(__outListData, __writebuf, DMA_WRITE);
+    if (outListData->length > 0) {
+        scheduler->dma_storeList(outListData, writebuf, DMA_WRITE);
 
 #if defined(NO_PIPELINE)
-        __scheduler->dma_wait(DMA_WRITE);
-        free(__writebuf);
+        scheduler->dma_wait(DMA_WRITE);
+        free(writebuf);
 #endif
     }
 
@@ -227,11 +227,11 @@
     __debug("[SchedTask:%s]\n", __FUNCTION__);
 
 #if !defined(NO_PIPELINE)
-    __scheduler->dma_wait(DMA_WRITE);
-    free(__writebuf);
+    scheduler->dma_wait(DMA_WRITE);
+    free(writebuf);
 #endif
 
-    if (__task->self == MY_SPE_NOP) return;
+    if (task->self == MY_SPE_NOP) return;
 
     (this->*ex_write)();
 }
@@ -284,8 +284,8 @@
      * このタスク内で新たにタスクが生成されなかった
      * or 生成されたが、そのタスクの終了を待つ必要は無い
      */
-    if (__renew_flag == 0) {
-        __scheduler->mail_write(__task->self);
+    if (renew_flag == 0) {
+        scheduler->mail_write(task->self);
     }
 }
 
@@ -306,13 +306,13 @@
 {
     uint32 cmd;
 
-    __taskGroup->remove(__task);
-    cmd = __taskGroup->status();
+    taskGroup->remove(task);
+    cmd = taskGroup->status();
 
     // タスク内で作られた全てのタスクが終了した
     if (cmd != 0) {
-        delete __taskGroup;
-        __scheduler->mail_write(cmd);
+        delete taskGroup;
+        scheduler->mail_write(cmd);
     }
 }
 
@@ -329,36 +329,36 @@
 SchedTaskBase*
 SchedTask::ex_next_normal()
 {
-    if (__cur_index < __list->length) {
+    if (cur_index < list->length) {
         SchedTaskBase *nextSched;
 
-        nextSched = __scheduler->get_nextRenewTaskList();
+        nextSched = scheduler->get_nextRenewTaskList();
 
         // RenewTask がある
         if (nextSched) {
-            __scheduler->set_backupTaskList(__list);
-            __scheduler->set_backupTaskListIndex(__cur_index);
+            scheduler->set_backupTaskList(list);
+            scheduler->set_backupTaskListIndex(cur_index);
             return nextSched;
         } else {
-            TaskPtr nextTask = &__list->tasks[__cur_index++];
-	    if (__cur_index < __list->length) {
+            TaskPtr nextTask = &list->tasks[cur_index++];
+	    if (cur_index < list->length) {
 		// load next task
-		loadSchedTask(__scheduler, &__list->tasks[__cur_index]);
+		loadSchedTask(scheduler, &list->tasks[cur_index]);
 	    }
-            nextSched = createSchedTask(__scheduler, nextTask);
-            ((SchedTask*)nextSched)->__init__(__list, nextTask, __cur_index,
-                                              __scheduler->get_curReadBuf(),
-                                              __scheduler->get_curWriteBuf(),
-                                              __scheduler);
+            nextSched = createSchedTask(scheduler, nextTask);
+            ((SchedTask*)nextSched)->init(list, nextTask, cur_index,
+                                              scheduler->get_curReadBuf(),
+                                              scheduler->get_curWriteBuf(),
+                                              scheduler);
             return nextSched;
         }
     } else {
-        uint32 nextList = (uint32)__list->next;
+        uint32 nextList = (uint32)list->next;
 
         if (nextList == 0) {
-            return new SchedNop2Ready(__scheduler);
+            return new SchedNop2Ready(scheduler);
         } else {
-            return createSchedTaskList(nextList, __scheduler,
+            return createSchedTaskList(nextList, scheduler,
                                        SCHED_TASKLIST_NORMAL);
         }
     }
@@ -373,54 +373,54 @@
     TaskPtr nextTask;
     SchedTask *nextSched;
 
-    if (__cur_index < __list->length) {
-        nextTask = &__list->tasks[__cur_index++];
-	if (__cur_index < __list->length) {
+    if (cur_index < list->length) {
+        nextTask = &list->tasks[cur_index++];
+	if (cur_index < list->length) {
 	    // load next task
-	    loadSchedTask(__scheduler, &__list->tasks[__cur_index]);
+	    loadSchedTask(scheduler, &list->tasks[cur_index]);
 	}
-        nextSched = createSchedTask(__scheduler, nextTask);
+        nextSched = createSchedTask(scheduler, nextTask);
 
         // RenewTaskList を実行中なので
-        nextSched->__setRenew();
-        nextSched->__init__(__list, nextTask, __cur_index,
-                            __scheduler->get_curReadBuf(),
-                            __scheduler->get_curWriteBuf(),
-                            __scheduler);
+        nextSched->setRenew();
+        nextSched->init(list, nextTask, cur_index,
+                            scheduler->get_curReadBuf(),
+                            scheduler->get_curWriteBuf(),
+                            scheduler);
 
         /**
          * この理由は SchedTask:~SchedTask() で
          */
-        __list = NULL;
+        list = NULL;
         return nextSched;
     } else {
         SchedTaskBase *nextList;
 
-        nextList = __scheduler->get_nextRenewTaskList();
+        nextList = scheduler->get_nextRenewTaskList();
 
         if (nextList) {
             return nextList;
         } else {
-            TaskListPtr nextList = __scheduler->get_backupTaskList();
+            TaskListPtr nextList = scheduler->get_backupTaskList();
 
             // 中断した TaskList がある
             if (nextList) {
-                __cur_index = __scheduler->get_backupTaskListIndex();
+                cur_index = scheduler->get_backupTaskListIndex();
 
-                nextTask = &nextList->tasks[__cur_index++];
-		if (__cur_index < __list->length) {
+                nextTask = &nextList->tasks[cur_index++];
+		if (cur_index < list->length) {
 		    // load next task
-		    loadSchedTask(__scheduler, &__list->tasks[__cur_index]);
+		    loadSchedTask(scheduler, &list->tasks[cur_index]);
 		}
-                nextSched = createSchedTask(__scheduler, nextTask);
+                nextSched = createSchedTask(scheduler, nextTask);
 
-                nextSched->__init__(nextList, nextTask, __cur_index,
-                                    __scheduler->get_curReadBuf(),
-                                    __scheduler->get_curWriteBuf(),
-                                    __scheduler);
+                nextSched->init(nextList, nextTask, cur_index,
+                                    scheduler->get_curReadBuf(),
+                                    scheduler->get_curWriteBuf(),
+                                    scheduler);
                 return nextSched;
             } else {
-                return new SchedNop2Ready(__scheduler);
+                return new SchedNop2Ready(scheduler);
             }
         }
     }
@@ -429,7 +429,7 @@
 int
 SchedTask::get_cpuid()
 {
-    return __scheduler->id;
+    return scheduler->id;
 }
 
 /**
@@ -440,7 +440,7 @@
 SchedTask::get_input(void *buff, int index)
 {
     if (buff != NULL) {
-        return (void*)((int)buff + __inListData->bound[index]);
+        return (void*)((int)buff + inListData->bound[index]);
     } else {
         return NULL;
     }
@@ -452,7 +452,7 @@
 uint32
 SchedTask::get_inputAddr(int index)
 {
-    return __inListData->element[index].addr;
+    return inListData->element[index].addr;
 }
 
 /**
@@ -461,7 +461,7 @@
 int
 SchedTask::get_inputSize(int index)
 {
-    return __inListData->element[index].size;
+    return inListData->element[index].size;
 }
 
 /**
@@ -471,7 +471,7 @@
 SchedTask::get_output(void *buff, int index)
 {
     if (buff != NULL) {
-        return (void*)((int)buff + __outListData->bound[index]);
+        return (void*)((int)buff + outListData->bound[index]);
     } else {
         return NULL;
     }
@@ -483,7 +483,7 @@
 uint32
 SchedTask::get_outputAddr(int index)
 {
-    return __outListData->element[index].addr;
+    return outListData->element[index].addr;
 }
 
 /**
@@ -492,24 +492,24 @@
 int
 SchedTask::get_outputSize(int index)
 {
-    return __outListData->element[index].size;
+    return outListData->element[index].size;
 }
 
 int
 SchedTask::get_param(int index)
 {
-    return __task->param[index];
+    return task->param[index];
 }
 
 TaskPtr
 SchedTask::create_task(int cmd)
 {
-    TaskListPtr taskList = __scheduler->get_renewListBuf();
+    TaskListPtr taskList = scheduler->get_renewListBuf();
     TaskPtr p = &taskList->tasks[taskList->length++];
     p->command = cmd;
 
-    p->inData = (ListData*)__scheduler->allocate(sizeof(ListData));
-    p->outData = (ListData*)__scheduler->allocate(sizeof(ListData));
+    p->inData = (ListData*)scheduler->allocate(sizeof(ListData));
+    p->outData = (ListData*)scheduler->allocate(sizeof(ListData));
 
     p->inData->clear();
     p->outData->clear();
@@ -521,97 +521,95 @@
 }
 
 /**
- * 生成したタスクが終了してから、メインスケジューラ(PPE) に
- * タスクが終了した旨を知らせる。
  *
- * @param[in] waitTask タスク内で生成したタスク
+ * @param[in] waitTask タスク内で生成したタスクの登録(spawn()に相当)
  */
 void
 SchedTask::wait_task(TaskPtr waitTask)
 {
-    waitTask->self = (uint32)__taskGroup;
+    waitTask->self = (uint32)taskGroup;
 
-    __scheduler->add_groupTask(__taskGroup, waitTask);
+    scheduler->add_groupTask(taskGroup, waitTask);
 
-    __renew_flag++;
+    renew_flag++;
 }
 
 void*
 SchedTask::global_alloc(int id, int size) {
-    return __scheduler->global_alloc(id, size);
+    return scheduler->global_alloc(id, size);
 }
 
 void*
 SchedTask::global_get(int id) {
-    return __scheduler->global_get(id);
+    return scheduler->global_get(id);
 }
 
 void
 SchedTask::global_set(int id, void *addr) {
-    __scheduler->global_set(id, addr);
+    scheduler->global_set(id, addr);
 }
 
 void
 SchedTask::global_free(int id) {
-    __scheduler->global_free(id);
+    scheduler->global_free(id);
 }
 
 MemList*
 SchedTask::createMemList(int size, int count) {
-    return __scheduler->createMemList(size, count);
+    return scheduler->createMemList(size, count);
 }
 
 void
 SchedTask::mainMem_alloc(int id, int size) {
-    __scheduler->mainMem_alloc(id, size);
+    scheduler->mainMem_alloc(id, size);
 }
 
 void
 SchedTask::mainMem_wait() {
-    __scheduler->mainMem_wait();
+    scheduler->mainMem_wait();
 }
 
 void*
 SchedTask::mainMem_get(int id) {
-    return __scheduler->mainMem_get(id);
+    return scheduler->mainMem_get(id);
 }
 
 void*
 SchedTask::allocate(int size) {
-    return __scheduler->allocate(size);
+    return scheduler->allocate(size);
 }
 
 
 void
 SchedTask::dma_load(void *buf, uint32 addr, uint32 size, uint32 mask) {
-    __scheduler->dma_load(buf, addr, size, mask);
+    scheduler->dma_load(buf, addr, size, mask);
 }
 
 void
 SchedTask::dma_store(void *buf,uint32 addr, uint32 size, uint32 mask) {
-    __scheduler->dma_store(buf, addr, size, mask);
+    scheduler->dma_store(buf, addr, size, mask);
 }
 
 void
 SchedTask::dma_wait(uint32 mask) {
-    __scheduler->dma_wait(mask);
+    scheduler->dma_wait(mask);
 }
 
 void
 SchedTask::show_dma_wait() {
-    __scheduler->show_dma_wait();
+    scheduler->show_dma_wait();
 }
 
 MemorySegment * SchedTask::get_segment(memaddr addr, MemList *m) {
-    return __scheduler->get_segment(addr,m);
+    return scheduler->get_segment(addr,m);
 }
 
 void SchedTask::put_segment(MemorySegment *s) {
-    __scheduler->put_segment(s);
+    scheduler->put_segment(s);
 }
 
 void SchedTask::wait_segment(MemorySegment *s) {
-    __scheduler->wait_segment(s);
+    scheduler->wait_segment(s);
 }
 
 /* system call */
--- a/TaskManager/kernel/schedule/SchedTask.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/schedule/SchedTask.h	Tue Oct 06 14:22:41 2009 +0900
@@ -22,15 +22,15 @@
     /* variables */
 
     // Task を実行するスケジューラ自身
-    Scheduler *__scheduler;
+    Scheduler *scheduler;
     
     // 現在スケジューラが実行している TaskList と、このタスクに対応する Task
-    TaskListPtr __list;
-    TaskPtr __task;
+    TaskListPtr list;
+    TaskPtr task;
 
     // read/write 用の ListData
-    ListDataPtr __inListData;
-    ListDataPtr __outListData;
+    ListDataPtr inListData;
+    ListDataPtr outListData;
 
     /**
      * read データ、write 用のバッファ
@@ -38,24 +38,24 @@
      * writebuf にデータを描き込んでおくと、
      * タスク登録時に設定した出力先に書き込む
      */
-    void *__readbuf;
-    void *__writebuf;
+    void *readbuf;
+    void *writebuf;
 
     // Task の、Tasklist での位置。(task = &list[cur_index-1])
-    int __cur_index;
+    int cur_index;
 
     // タスク内で生成されたタスクのグループ
-    TaskGroup *__taskGroup;
+    TaskGroup *taskGroup;
 
     // このタスク内で生成されたタスクの数
-    int __renew_flag;
+    int renew_flag;
 
     // このタスクが SPE 内で生成されたタスクか否か 1: Yes, 0: No
-    int __flag_renewTask;
+    int flag_renewTask;
 
     // タスクがメインメモリ側で生成されたものか、
     // SPE で生成されたものかによって、データの扱いが変わってくる。
-    // そのために if (__flag_renewTask) を連発するのはよくないので
+    // そのために if (flag_renewTask) を連発するのはよくないので
     // 関数ポインタで持っておく
     void (SchedTask::*ex_init)();
     void (SchedTask::*ex_read)();
@@ -78,7 +78,7 @@
 
     /**
      * PPE で生成されたタスクに対する
-     * __init__, read,exec,write,next の付属(?)処理
+     * init, read,exec,write,next の付属(?)処理
      */
     void ex_init_normal();
     void ex_read_normal();
@@ -88,7 +88,7 @@
 
     /**
      * SPE で生成されたタスクに対する
-     * __inti__, ead,exec,write,next の付属(?)処理
+     * inti, ead,exec,write,next の付属(?)処理
      */
     void ex_init_renew();
     void ex_read_renew();
@@ -99,8 +99,8 @@
 public:
     /* functions */
 
-    void __setRenew();
-    void __init__(TaskListPtr _list, TaskPtr _task, int index,
+    void setRenew();
+    void init(TaskListPtr _list, TaskPtr _task, int index,
                   ListDataPtr rbuf, ListDataPtr wbuf, Scheduler* sc);
 
     //---  User API ---
@@ -136,7 +136,7 @@
 
     void *allocate(int size);
     void free_(void *p) {
-	__scheduler->free_(p);
+	scheduler->free_(p);
     }
 
     void dma_load(void *buf, uint32 addr, uint32 size, uint32 mask);
@@ -149,11 +149,11 @@
      */
 
     void* get_input(int index) {
-      return get_input(__readbuf, index);
+      return get_input(readbuf, index);
     }
 
     void* get_output(int index) {
-      return get_output(__writebuf, index);
+      return get_output(writebuf, index);
     }
 
     /* system call */
--- a/TaskManager/kernel/schedule/SchedTaskList.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/schedule/SchedTaskList.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -77,10 +77,10 @@
 	nextSched = createSchedTask(scheduler, nextTask);
 
 	if (flag_renewTaskList == SCHED_TASKLIST_RENEW) {
-	    ((SchedTask*)nextSched)->__setRenew();
+	    ((SchedTask*)nextSched)->setRenew();
 	}
 	
-	((SchedTask*)nextSched)->__init__(list, nextTask, 1,
+	((SchedTask*)nextSched)->init(list, nextTask, 1,
 					  scheduler->get_curReadBuf(),
 					  scheduler->get_curWriteBuf(),
 					  scheduler);
--- a/TaskManager/kernel/schedule/Scheduler.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/schedule/Scheduler.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -50,6 +50,7 @@
     taskGroup = new TaskGroup;
     renewTop_taskList = NULL;
     renewCur_taskList = NULL;
+    bak_curTaskList = NULL;
 }
 
 void
--- a/TaskManager/kernel/schedule/TaskGroup.h	Tue Oct 06 14:21:37 2009 +0900
+++ b/TaskManager/kernel/schedule/TaskGroup.h	Tue Oct 06 14:22:41 2009 +0900
@@ -2,16 +2,19 @@
 #define INCLUDED_TASK_GROUP
 
 #include "base.h"
+#include "Task.h"
 #include "TaskQueue.h"
 
 class TaskGroup {
 public:
-    TaskGroup(void): group(NULL) {}
+    TaskGroup(): group(NULL) {}
 
     BASE_NEW_DELETE(TaskGroup);
 
+    // この command を引き渡すだけのためのオブジェクトらしい
+
     unsigned int command;
-    TaskQueuePtr group;
+    TaskQueue *group;
 
     /**
      * 待つ Task を追加
--- a/example/dependency_task/main.cc	Tue Oct 06 14:21:37 2009 +0900
+++ b/example/dependency_task/main.cc	Tue Oct 06 14:22:41 2009 +0900
@@ -16,7 +16,7 @@
 void
 run_start(TaskManager *manager)
 {
-    HTaskPtr t_exec;
+    HTaskPtr t_exec[2];
     HTaskPtr t_print;
 
     idata = (int*)manager->allocate(sizeof(int)*length*2);
@@ -31,21 +31,23 @@
 
     // idata を二つに分けて計算する
     for (int i = 0; i < 2; i++) {
-	t_exec = manager->create_task(TASK_EXEC);
-	t_exec->add_inData(&idata[length*i], sizeof(int)*length);
-	t_exec->add_outData(&idata[length*i], sizeof(int)*length);
-	t_exec->add_param(length);
-	t_exec->add_param(13*(i+1));
-	t_exec->set_cpu(SPE_ANY);
+	t_exec[i] = manager->create_task(TASK_EXEC);
+	t_exec[i]->add_inData(&idata[length*i], sizeof(int)*length);
+	t_exec[i]->add_outData(&idata[length*i], sizeof(int)*length);
+	t_exec[i]->add_param(length);
+	t_exec[i]->add_param(13*(i+1));
+	t_exec[i]->set_cpu(SPE_ANY);
 
 	if (depend_flg)
-	    t_print->wait_for(t_exec);
-	
-	t_exec->spawn();
+	    t_print->wait_for(t_exec[i]);
     }
 
     // add Active Queue
     t_print->spawn();
+
+    for (int i = 0; i < 2; i++) {
+	t_exec[i]->spawn();
+    }
 }
 
 int