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