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

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