annotate TaskManager/Fifo/FifoTaskManagerImpl.cc @ 9:964b3b27846d

*** empty log message ***
author gongo
date Wed, 06 Feb 2008 18:31:30 +0900
parents b02b69ebb89a
children 7aa4c006e4be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
1 #include <stdio.h>
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
2 #include <stdlib.h>
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
3 #include <string.h>
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
4 #include "FifoTaskManagerImpl.h"
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
5 #include "ppe_spe.h"
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
6
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
7 void
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
8 FifoTaskManagerImpl::init(void)
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
9 {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
10 taskInfo = new FifoTaskInfo();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
11 taskInfo->init();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
12
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
13 mailManager = new MailManager();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
14 mailManager->init_pool_mailQueue(20);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
15 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
16
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
17 TaskListPtr
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
18 FifoTaskManagerImpl::set_task(void)
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
19 {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
20 // ここ...直すかな
9
964b3b27846d *** empty log message ***
gongo
parents: 8
diff changeset
21 TaskListPtr list = taskInfo->machineTaskList[0];
964b3b27846d *** empty log message ***
gongo
parents: 8
diff changeset
22 TaskQueuePtr queue = taskInfo->activeTaskQueue;
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
23 TaskQueuePtr d;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
24 HTaskPtr htask;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
25 TaskPtr task;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
26
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
27 if (queue == NULL) {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
28 return NULL;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
29 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
30
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
31 // Fixme
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
32 // ここは、clear_taskList とか?
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
33 list->length = 0;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
34
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
35 while (queue) {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
36 htask = queue->task;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
37 d = queue;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
38 queue = queue->next;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
39
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
40 task = &list->tasks[list->length++];
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
41 task->command = htask->command;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
42 task->in_addr = htask->in_addr;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
43 task->out_addr = htask->out_addr;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
44 task->in_size = htask->in_size;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
45 task->self = htask;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
46
9
964b3b27846d *** empty log message ***
gongo
parents: 8
diff changeset
47 taskInfo->free_taskQueue(d);
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
48 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
49
9
964b3b27846d *** empty log message ***
gongo
parents: 8
diff changeset
50 taskInfo->activeTaskQueue = NULL;
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
51
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
52 return list;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
53 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
54
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
55 // ../spe/main.cpp
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
56 extern MailQueuePtr spe_main(MailManager*, MailQueuePtr);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
57
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
58 /**
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
59 * spe 側は MY_SPE_COMMAND_EXIT を受け取るまでは別スレッドで動き続ける。
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
60 * fifo version では sequential に動かすため、
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
61 * mail list の最後に番兵として MY_SPE_COMMAND_EXIT のメールを入れる。
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
62 * これで、fifo での spe 側は、mail で受け取った task_list を処理した後
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
63 * EXIT を受け取って終了する・・・といいな
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
64 */
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
65 void
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
66 FifoTaskManagerImpl::run(void)
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
67 {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
68 TaskListPtr list;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
69 MailQueuePtr mail_list = NULL;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
70 MailQueuePtr list_mail = NULL; // task list
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
71 MailQueuePtr sentinel = NULL; // 番兵
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
72
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
73 // 暫定
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
74 list = set_task();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
75
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
76 list_mail = mailManager->create_mail((unsigned int)list);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
77 mail_list = append_mailQueue(mail_list, list_mail);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
78
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
79 do {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
80 sentinel = mailManager->create_mail(MY_SPE_COMMAND_EXIT);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
81 mail_list = append_mailQueue(mail_list, sentinel);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
82
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
83 // 返って来た mail_list には、spe からの mail がある
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
84 mail_list = spe_main(mailManager, mail_list);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
85 mail_list = mail_check(mail_list);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
86 } while (mail_list);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
87 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
88
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
89 MailQueuePtr
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
90 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list)
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
91 {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
92 MailQueuePtr q = mail_list;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
93 MailQueuePtr d;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
94 MailQueuePtr ret = NULL;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
95 unsigned int data;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
96 TaskListPtr next_list;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
97
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
98 while (q) {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
99 data = q->data;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
100
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
101 if (data == MY_SPE_STATUS_READY) {
8
b02b69ebb89a *** empty log message ***
gongo
parents: 3
diff changeset
102 //printf("[FIFO] finish\n");
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
103 next_list = set_task();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
104 if (next_list != NULL) {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
105 d = mailManager->create_mail((unsigned int)next_list);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
106 ret = append_mailQueue(ret, d);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
107 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
108 } else {
8
b02b69ebb89a *** empty log message ***
gongo
parents: 3
diff changeset
109 //printf("[PPE] recv from : 0x%x\n", data);
3
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
110 taskInfo->check_task_finish((HTaskPtr)data);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
111 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
112
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
113 d = q;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
114 q = q->next;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
115
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
116 mailManager->free_mailQueue(d);
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
117 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
118
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
119 return ret;
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
120 }
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
121
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
122
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
123 TaskManagerImpl*
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
124 create_impl(int num)
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
125 {
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
126 return new FifoTaskManagerImpl();
2356238ebea7 *** empty log message ***
gongo
parents:
diff changeset
127 }