diff TaskManager/Fifo/FifoTaskManagerImpl.cc @ 3:2356238ebea7

*** empty log message ***
author gongo
date Tue, 05 Feb 2008 20:22:50 +0900
parents
children b02b69ebb89a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Fifo/FifoTaskManagerImpl.cc	Tue Feb 05 20:22:50 2008 +0900
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "FifoTaskManagerImpl.h"
+#include "ppe_spe.h"
+
+void
+FifoTaskManagerImpl::init(void)
+{
+    taskInfo = new FifoTaskInfo();
+    taskInfo->init();
+
+    mailManager = new MailManager();
+    mailManager->init_pool_mailQueue(20);
+}
+
+TaskListPtr
+FifoTaskManagerImpl::set_task(void)
+{
+    // ここ...直すかな
+    FifoTaskInfo *info = (FifoTaskInfo*)taskInfo;
+    TaskListPtr list = info->machineTaskList;
+    TaskQueuePtr queue = info->activeTaskQueue;
+    TaskQueuePtr d;
+    HTaskPtr htask;
+    TaskPtr task;
+
+    if (queue == NULL) {
+	return NULL;
+    }
+
+    // Fixme
+    // ここは、clear_taskList とか?
+    list->length = 0;
+
+    while (queue) {
+	htask = queue->task;
+	d = queue;
+	queue = queue->next;
+
+	task = &list->tasks[list->length++];
+	task->command  = htask->command;
+	task->in_addr  = htask->in_addr;
+	task->out_addr = htask->out_addr;
+	task->in_size  = htask->in_size;
+	task->self = htask;
+
+	info->free_taskQueue(d);
+    }	
+
+    info->activeTaskQueue = NULL;
+
+    return list;
+}
+
+// ../spe/main.cpp
+extern MailQueuePtr spe_main(MailManager*, MailQueuePtr);
+
+/**
+ * spe 側は MY_SPE_COMMAND_EXIT を受け取るまでは別スレッドで動き続ける。
+ * fifo version では sequential に動かすため、
+ * mail list の最後に番兵として MY_SPE_COMMAND_EXIT のメールを入れる。
+ * これで、fifo での spe 側は、mail で受け取った task_list を処理した後
+ * EXIT を受け取って終了する・・・といいな
+ */
+void
+FifoTaskManagerImpl::run(void)
+{
+    TaskListPtr list;
+    MailQueuePtr mail_list = NULL;
+    MailQueuePtr list_mail = NULL; // task list
+    MailQueuePtr sentinel = NULL;  // 番兵
+
+    // 暫定
+    list = set_task();
+
+    list_mail =	mailManager->create_mail((unsigned int)list);
+    mail_list = append_mailQueue(mail_list, list_mail);
+	
+    do {
+	sentinel  = mailManager->create_mail(MY_SPE_COMMAND_EXIT);
+	mail_list = append_mailQueue(mail_list, sentinel);
+
+	// 返って来た mail_list には、spe からの mail がある
+	mail_list = spe_main(mailManager, mail_list);
+	mail_list = mail_check(mail_list);
+    } while (mail_list);
+}
+
+MailQueuePtr
+FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list)
+{
+    MailQueuePtr q = mail_list;
+    MailQueuePtr d;
+    MailQueuePtr ret = NULL;
+    unsigned int data;
+    TaskListPtr next_list;
+
+    while (q) {
+	data = q->data;
+
+	if (data == MY_SPE_STATUS_READY) {
+	    printf("[FIFO] finish\n");
+	    next_list = set_task();
+	    if (next_list != NULL) {
+		d = mailManager->create_mail((unsigned int)next_list);
+		ret = append_mailQueue(ret, d);
+	    }
+	} else {
+	    printf("[PPE] recv from : 0x%x\n", data);
+	    taskInfo->check_task_finish((HTaskPtr)data);
+	}
+
+	d = q;
+	q = q->next;
+
+	mailManager->free_mailQueue(d);
+    }
+
+    return ret;
+}
+
+
+TaskManagerImpl*
+create_impl(int num)
+{
+    return new FifoTaskManagerImpl();
+}