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