Mercurial > hg > Game > Cerium
comparison Document/document/html/FifoTaskManagerImpl_8cc-source.html @ 291:d7803cea25a3 draft
document
author | kono@localhost.localdomain |
---|---|
date | Fri, 05 Jun 2009 18:16:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
290:d5c479b69b46 | 291:d7803cea25a3 |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | |
3 <title>Cerium: FifoTaskManagerImpl.cc Source File</title> | |
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> | |
5 <link href="tabs.css" rel="stylesheet" type="text/css"> | |
6 </head><body> | |
7 <!-- Generated by Doxygen 1.5.7.1 --> | |
8 <div class="navigation" id="top"> | |
9 <div class="tabs"> | |
10 <ul> | |
11 <li><a href="index.html"><span>Main Page</span></a></li> | |
12 <li><a href="annotated.html"><span>Classes</span></a></li> | |
13 <li class="current"><a href="files.html"><span>Files</span></a></li> | |
14 </ul> | |
15 </div> | |
16 <div class="tabs"> | |
17 <ul> | |
18 <li><a href="files.html"><span>File List</span></a></li> | |
19 </ul> | |
20 </div> | |
21 <h1>FifoTaskManagerImpl.cc</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include <stdio.h></span> | |
22 <a name="l00002"></a>00002 <span class="preprocessor">#include <stdlib.h></span> | |
23 <a name="l00003"></a>00003 <span class="preprocessor">#include <string.h></span> | |
24 <a name="l00004"></a>00004 <span class="preprocessor">#include "FifoTaskManagerImpl.h"</span> | |
25 <a name="l00005"></a>00005 <span class="preprocessor">#include "types.h"</span> | |
26 <a name="l00006"></a>00006 <span class="preprocessor">#include "error.h"</span> | |
27 <a name="l00007"></a>00007 | |
28 <a name="l00008"></a>00008 FifoTaskManagerImpl::~FifoTaskManagerImpl(<span class="keywordtype">void</span>) | |
29 <a name="l00009"></a>00009 { | |
30 <a name="l00010"></a>00010 <span class="keyword">delete</span> mailManager; | |
31 <a name="l00011"></a>00011 <span class="keyword">delete</span> scheduler; | |
32 <a name="l00012"></a>00012 <span class="keyword">delete</span> bufferManager; | |
33 <a name="l00013"></a>00013 } | |
34 <a name="l00014"></a>00014 | |
35 <a name="l00020"></a>00020 <span class="keywordtype">void</span> | |
36 <a name="l00021"></a>00021 FifoTaskManagerImpl::init(<span class="keywordtype">void</span>) | |
37 <a name="l00022"></a>00022 { | |
38 <a name="l00023"></a>00023 mailManager = <span class="keyword">new</span> MailManager(); | |
39 <a name="l00024"></a>00024 mailManager->init(20); | |
40 <a name="l00025"></a>00025 | |
41 <a name="l00026"></a>00026 scheduler = <span class="keyword">new</span> MainScheduler(); | |
42 <a name="l00027"></a>00027 scheduler->init(); | |
43 <a name="l00028"></a>00028 scheduler->set_mailManager(mailManager); | |
44 <a name="l00029"></a>00029 scheduler->id = 0; | |
45 <a name="l00030"></a>00030 | |
46 <a name="l00031"></a>00031 bufferManager = <span class="keyword">new</span> <a class="code" href="classBufferManager.html">BufferManager</a>; | |
47 <a name="l00032"></a>00032 bufferManager->init(); | |
48 <a name="l00033"></a>00033 | |
49 <a name="l00034"></a>00034 mainTaskList = bufferManager->create_taskList(); | |
50 <a name="l00035"></a>00035 } | |
51 <a name="l00036"></a>00036 | |
52 <a name="l00043"></a>00043 <span class="keywordtype">void</span> | |
53 <a name="l00044"></a>00044 FifoTaskManagerImpl::init(MainScheduler *_sched, <a class="code" href="classBufferManager.html">BufferManager</a> *buff) | |
54 <a name="l00045"></a>00045 { | |
55 <a name="l00046"></a>00046 mailManager = <span class="keyword">new</span> MailManager(); | |
56 <a name="l00047"></a>00047 mailManager->init(20); | |
57 <a name="l00048"></a>00048 | |
58 <a name="l00049"></a>00049 <span class="comment">//scheduler = new MainScheduler();</span> | |
59 <a name="l00050"></a>00050 scheduler = _sched; | |
60 <a name="l00051"></a>00051 scheduler->init(); | |
61 <a name="l00052"></a>00052 scheduler->set_mailManager(mailManager); | |
62 <a name="l00053"></a>00053 | |
63 <a name="l00054"></a>00054 bufferManager = buff; | |
64 <a name="l00055"></a>00055 | |
65 <a name="l00056"></a>00056 mainTaskList = bufferManager-><a class="code" href="classBufferManager.html#9dd8ede25545cff6ab9e1bb6936967d1">create_taskList</a>(); | |
66 <a name="l00057"></a>00057 } | |
67 <a name="l00058"></a>00058 | |
68 <a name="l00067"></a>00067 TaskListPtr | |
69 <a name="l00068"></a>00068 FifoTaskManagerImpl::get_runTaskList(<span class="keywordtype">void</span>) | |
70 <a name="l00069"></a>00069 { | |
71 <a name="l00070"></a>00070 TaskListPtr list, list_top; | |
72 <a name="l00071"></a>00071 TaskQueuePtr queue; | |
73 <a name="l00072"></a>00072 TaskQueuePtr d; | |
74 <a name="l00073"></a>00073 HTaskPtr htask; <span class="comment">// HTask (PPE にある)</span> | |
75 <a name="l00074"></a>00074 TaskPtr task; <span class="comment">// Task (SPE に送る Task)</span> | |
76 <a name="l00075"></a>00075 | |
77 <a name="l00076"></a>00076 queue = activeTaskQueue; | |
78 <a name="l00077"></a>00077 <span class="keywordflow">if</span> (queue == NULL) { | |
79 <a name="l00078"></a>00078 <span class="keywordflow">return</span> NULL; | |
80 <a name="l00079"></a>00079 } | |
81 <a name="l00080"></a>00080 | |
82 <a name="l00081"></a>00081 <span class="comment">// PPE 側で実行される TaskList</span> | |
83 <a name="l00082"></a>00082 list_top = mainTaskList; | |
84 <a name="l00083"></a>00083 | |
85 <a name="l00084"></a>00084 <span class="comment">// list_top->clear() とかの方がいいかもしれん。</span> | |
86 <a name="l00085"></a>00085 list_top = bufferManager->clear_taskList(list_top); | |
87 <a name="l00086"></a>00086 list = list_top; | |
88 <a name="l00087"></a>00087 | |
89 <a name="l00088"></a>00088 <span class="keywordflow">while</span> (queue) { | |
90 <a name="l00089"></a>00089 htask = (HTaskPtr)queue->task; | |
91 <a name="l00090"></a>00090 d = queue; | |
92 <a name="l00091"></a>00091 queue = queue->next; | |
93 <a name="l00092"></a>00092 | |
94 <a name="l00093"></a>00093 task = &list->tasks[list->length++]; | |
95 <a name="l00094"></a>00094 | |
96 <a name="l00095"></a>00095 #<span class="keywordflow">if</span> 0 | |
97 <a name="l00096"></a>00096 task->command = htask->command; | |
98 <a name="l00097"></a>00097 task->inData = htask->inData; | |
99 <a name="l00098"></a>00098 task->outData = htask->outData; | |
100 <a name="l00099"></a>00099 task->self = (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)htask; | |
101 <a name="l00100"></a>00100 <span class="preprocessor">#else</span> | |
102 <a name="l00101"></a>00101 <span class="preprocessor"></span> memcpy(task, htask, <span class="keyword">sizeof</span>(Task)); | |
103 <a name="l00102"></a>00102 <span class="preprocessor">#endif</span> | |
104 <a name="l00103"></a>00103 <span class="preprocessor"></span> | |
105 <a name="l00104"></a>00104 <span class="keywordflow">if</span> (list->length >= TASK_MAX_SIZE) { | |
106 <a name="l00105"></a>00105 TaskListPtr newList = bufferManager->create_taskList(); | |
107 <a name="l00106"></a>00106 list_top = TaskListInfo::append(list_top, newList); | |
108 <a name="l00107"></a>00107 list = newList; | |
109 <a name="l00108"></a>00108 } | |
110 <a name="l00109"></a>00109 | |
111 <a name="l00110"></a>00110 bufferManager->free_taskQueue(d); | |
112 <a name="l00111"></a>00111 } | |
113 <a name="l00112"></a>00112 | |
114 <a name="l00113"></a>00113 activeTaskQueue = NULL; | |
115 <a name="l00114"></a>00114 mainTaskList = list_top; | |
116 <a name="l00115"></a>00115 | |
117 <a name="l00116"></a>00116 <span class="keywordflow">return</span> list_top; | |
118 <a name="l00117"></a>00117 } | |
119 <a name="l00118"></a>00118 | |
120 <a name="l00119"></a>00119 | |
121 <a name="l00120"></a>00120 <span class="keywordtype">void</span> | |
122 <a name="l00121"></a>00121 FifoTaskManagerImpl::run(<span class="keywordtype">void</span>) | |
123 <a name="l00122"></a>00122 { | |
124 <a name="l00123"></a>00123 TaskListPtr list; | |
125 <a name="l00124"></a>00124 MailQueuePtr mail; | |
126 <a name="l00125"></a>00125 | |
127 <a name="l00126"></a>00126 list = get_runTaskList(); | |
128 <a name="l00127"></a>00127 | |
129 <a name="l00128"></a>00128 <span class="keywordflow">do</span> { | |
130 <a name="l00129"></a>00129 <span class="comment">// list を実行する</span> | |
131 <a name="l00130"></a>00130 mail = schedule(list); | |
132 <a name="l00131"></a>00131 | |
133 <a name="l00132"></a>00132 <span class="comment">// mail には、ppe scheduler からの mail がある</span> | |
134 <a name="l00133"></a>00133 mail_check(mail); | |
135 <a name="l00134"></a>00134 | |
136 <a name="l00135"></a>00135 <span class="comment">// 依存関係を満たしたものは実行可能キューへ</span> | |
137 <a name="l00136"></a>00136 wakeup_waitTask(); | |
138 <a name="l00137"></a>00137 list = get_runTaskList(); | |
139 <a name="l00138"></a>00138 } <span class="keywordflow">while</span> (list); | |
140 <a name="l00139"></a>00139 } | |
141 <a name="l00140"></a>00140 | |
142 <a name="l00147"></a>00147 MailQueuePtr | |
143 <a name="l00148"></a>00148 FifoTaskManagerImpl::schedule(TaskListPtr list) | |
144 <a name="l00149"></a>00149 { | |
145 <a name="l00150"></a>00150 MailQueuePtr list_mail; <span class="comment">// task list</span> | |
146 <a name="l00151"></a>00151 MailQueuePtr sentinel; <span class="comment">// 番兵</span> | |
147 <a name="l00152"></a>00152 MailQueuePtr in_mail_list = NULL; | |
148 <a name="l00153"></a>00153 MailQueuePtr out_mail_list = NULL; | |
149 <a name="l00154"></a>00154 | |
150 <a name="l00155"></a>00155 <span class="comment">// TaskList のアドレス</span> | |
151 <a name="l00156"></a>00156 list_mail = mailManager->create((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)list); | |
152 <a name="l00157"></a>00157 in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail); | |
153 <a name="l00158"></a>00158 | |
154 <a name="l00159"></a>00159 <span class="comment">// EXIT_COMMAND (番兵的な意味で)</span> | |
155 <a name="l00160"></a>00160 sentinel = mailManager->create(MY_SPE_COMMAND_EXIT); | |
156 <a name="l00161"></a>00161 in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel); | |
157 <a name="l00162"></a>00162 | |
158 <a name="l00163"></a>00163 <span class="comment">// scheduler は受け取ったメールを元に実行する</span> | |
159 <a name="l00164"></a>00164 scheduler->send_mailList(in_mail_list); | |
160 <a name="l00165"></a>00165 scheduler->run(); | |
161 <a name="l00166"></a>00166 out_mail_list = scheduler->recv_mailList(); | |
162 <a name="l00167"></a>00167 | |
163 <a name="l00168"></a>00168 <span class="keywordflow">return</span> out_mail_list; | |
164 <a name="l00169"></a>00169 } | |
165 <a name="l00170"></a>00170 | |
166 <a name="l00181"></a>00181 <span class="keywordtype">void</span> | |
167 <a name="l00182"></a>00182 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list) | |
168 <a name="l00183"></a>00183 { | |
169 <a name="l00184"></a>00184 MailQueuePtr q = mail_list; | |
170 <a name="l00185"></a>00185 MailQueuePtr d; | |
171 <a name="l00186"></a>00186 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data; | |
172 <a name="l00187"></a>00187 | |
173 <a name="l00188"></a>00188 <span class="keywordflow">while</span> (q) { | |
174 <a name="l00189"></a>00189 data = q->data; | |
175 <a name="l00190"></a>00190 | |
176 <a name="l00200"></a>00200 <span class="keywordflow">if</span> (data == MY_SPE_STATUS_READY) { | |
177 <a name="l00201"></a>00201 __debug_ppe(<span class="stringliteral">"mail_check(): Task List finish\n"</span>); | |
178 <a name="l00202"></a>00202 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (data > MY_SPE_NOP) { | |
179 <a name="l00203"></a>00203 __debug_ppe(<span class="stringliteral">"mail_check(): recv from 0x%x\n"</span>, data); | |
180 <a name="l00204"></a>00204 check_task_finish((HTaskPtr)data); | |
181 <a name="l00205"></a>00205 } | |
182 <a name="l00206"></a>00206 | |
183 <a name="l00207"></a>00207 d = q; | |
184 <a name="l00208"></a>00208 q = q->next; | |
185 <a name="l00209"></a>00209 | |
186 <a name="l00210"></a>00210 mailManager->free(d); | |
187 <a name="l00211"></a>00211 } | |
188 <a name="l00212"></a>00212 } | |
189 <a name="l00213"></a>00213 | |
190 <a name="l00214"></a>00214 <span class="keywordtype">void</span> | |
191 <a name="l00215"></a>00215 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueuePtr *wait) | |
192 <a name="l00216"></a>00216 { | |
193 <a name="l00217"></a>00217 waitTaskQueue = *wait; | |
194 <a name="l00218"></a>00218 mail_check(mail_list); | |
195 <a name="l00219"></a>00219 } | |
196 <a name="l00220"></a>00220 | |
197 <a name="l00221"></a>00221 <span class="keywordtype">void</span>* | |
198 <a name="l00222"></a>00222 FifoTaskManagerImpl::allocate(<span class="keywordtype">int</span> size) | |
199 <a name="l00223"></a>00223 { | |
200 <a name="l00224"></a>00224 <span class="keywordflow">return</span> malloc(size); | |
201 <a name="l00225"></a>00225 } | |
202 <a name="l00226"></a>00226 | |
203 <a name="l00232"></a>00232 <span class="preprocessor">#ifdef __CERIUM_FIFO__</span> | |
204 <a name="l00233"></a>00233 <span class="preprocessor"></span>TaskManagerImpl* | |
205 <a name="l00234"></a>00234 create_impl(<span class="keywordtype">int</span> num) | |
206 <a name="l00235"></a>00235 { | |
207 <a name="l00236"></a>00236 <span class="keywordflow">return</span> <span class="keyword">new</span> FifoTaskManagerImpl(); | |
208 <a name="l00237"></a>00237 } | |
209 <a name="l00238"></a>00238 <span class="preprocessor">#endif // __CERIUM_FIFO__</span> | |
210 </pre></div></div> | |
211 <hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 5 18:14:06 2009 for Cerium by | |
212 <a href="http://www.doxygen.org/index.html"> | |
213 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.7.1 </small></address> | |
214 </body> | |
215 </html> |