view 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
line wrap: on
line source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Cerium: FifoTaskManagerImpl.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.7.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>FifoTaskManagerImpl.cc</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include "FifoTaskManagerImpl.h"</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include "types.h"</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include "error.h"</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 FifoTaskManagerImpl::~FifoTaskManagerImpl(<span class="keywordtype">void</span>)
<a name="l00009"></a>00009 {
<a name="l00010"></a>00010     <span class="keyword">delete</span> mailManager;
<a name="l00011"></a>00011     <span class="keyword">delete</span> scheduler;
<a name="l00012"></a>00012     <span class="keyword">delete</span> bufferManager;
<a name="l00013"></a>00013 }
<a name="l00014"></a>00014 
<a name="l00020"></a>00020 <span class="keywordtype">void</span>
<a name="l00021"></a>00021 FifoTaskManagerImpl::init(<span class="keywordtype">void</span>)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023     mailManager = <span class="keyword">new</span> MailManager();
<a name="l00024"></a>00024     mailManager-&gt;init(20);
<a name="l00025"></a>00025 
<a name="l00026"></a>00026     scheduler = <span class="keyword">new</span> MainScheduler();
<a name="l00027"></a>00027     scheduler-&gt;init();
<a name="l00028"></a>00028     scheduler-&gt;set_mailManager(mailManager);
<a name="l00029"></a>00029     scheduler-&gt;id = 0;
<a name="l00030"></a>00030 
<a name="l00031"></a>00031     bufferManager = <span class="keyword">new</span> <a class="code" href="classBufferManager.html">BufferManager</a>;
<a name="l00032"></a>00032     bufferManager-&gt;init();
<a name="l00033"></a>00033 
<a name="l00034"></a>00034     mainTaskList = bufferManager-&gt;create_taskList();
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036 
<a name="l00043"></a>00043 <span class="keywordtype">void</span>
<a name="l00044"></a>00044 FifoTaskManagerImpl::init(MainScheduler *_sched, <a class="code" href="classBufferManager.html">BufferManager</a> *buff)
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046     mailManager = <span class="keyword">new</span> MailManager();
<a name="l00047"></a>00047     mailManager-&gt;init(20);
<a name="l00048"></a>00048 
<a name="l00049"></a>00049     <span class="comment">//scheduler = new MainScheduler();</span>
<a name="l00050"></a>00050     scheduler = _sched;
<a name="l00051"></a>00051     scheduler-&gt;init();
<a name="l00052"></a>00052     scheduler-&gt;set_mailManager(mailManager);
<a name="l00053"></a>00053 
<a name="l00054"></a>00054     bufferManager = buff;
<a name="l00055"></a>00055 
<a name="l00056"></a>00056     mainTaskList = bufferManager-&gt;<a class="code" href="classBufferManager.html#9dd8ede25545cff6ab9e1bb6936967d1">create_taskList</a>();
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00067"></a>00067 TaskListPtr
<a name="l00068"></a>00068 FifoTaskManagerImpl::get_runTaskList(<span class="keywordtype">void</span>)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070     TaskListPtr list, list_top;
<a name="l00071"></a>00071     TaskQueuePtr queue;
<a name="l00072"></a>00072     TaskQueuePtr d;
<a name="l00073"></a>00073     HTaskPtr htask; <span class="comment">// HTask (PPE にある)</span>
<a name="l00074"></a>00074     TaskPtr task; <span class="comment">// Task (SPE に送る Task)</span>
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     queue = activeTaskQueue;
<a name="l00077"></a>00077     <span class="keywordflow">if</span> (queue == NULL) {
<a name="l00078"></a>00078         <span class="keywordflow">return</span> NULL;
<a name="l00079"></a>00079     }
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     <span class="comment">// PPE 側で実行される TaskList</span>
<a name="l00082"></a>00082     list_top = mainTaskList;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     <span class="comment">// list_top-&gt;clear() とかの方がいいかもしれん。</span>
<a name="l00085"></a>00085     list_top = bufferManager-&gt;clear_taskList(list_top);
<a name="l00086"></a>00086     list = list_top;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="keywordflow">while</span> (queue) {
<a name="l00089"></a>00089         htask = (HTaskPtr)queue-&gt;task;
<a name="l00090"></a>00090         d = queue;
<a name="l00091"></a>00091         queue = queue-&gt;next;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         task = &amp;list-&gt;tasks[list-&gt;length++];
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 #<span class="keywordflow">if</span> 0
<a name="l00096"></a>00096         task-&gt;command  = htask-&gt;command;
<a name="l00097"></a>00097         task-&gt;inData   = htask-&gt;inData;
<a name="l00098"></a>00098         task-&gt;outData  = htask-&gt;outData;
<a name="l00099"></a>00099         task-&gt;self     = (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)htask;
<a name="l00100"></a>00100 <span class="preprocessor">#else</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span>        memcpy(task, htask, <span class="keyword">sizeof</span>(Task));
<a name="l00102"></a>00102 <span class="preprocessor">#endif</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span>
<a name="l00104"></a>00104         <span class="keywordflow">if</span> (list-&gt;length &gt;= TASK_MAX_SIZE) {
<a name="l00105"></a>00105             TaskListPtr newList = bufferManager-&gt;create_taskList();
<a name="l00106"></a>00106             list_top = TaskListInfo::append(list_top, newList);
<a name="l00107"></a>00107             list = newList;
<a name="l00108"></a>00108         }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         bufferManager-&gt;free_taskQueue(d);
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     activeTaskQueue = NULL;
<a name="l00114"></a>00114     mainTaskList = list_top;
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     <span class="keywordflow">return</span> list_top;
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 
<a name="l00120"></a>00120 <span class="keywordtype">void</span>
<a name="l00121"></a>00121 FifoTaskManagerImpl::run(<span class="keywordtype">void</span>)
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123     TaskListPtr list;
<a name="l00124"></a>00124     MailQueuePtr mail;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     list = get_runTaskList();
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     <span class="keywordflow">do</span> {
<a name="l00129"></a>00129         <span class="comment">// list を実行する</span>
<a name="l00130"></a>00130         mail = schedule(list);
<a name="l00131"></a>00131 
<a name="l00132"></a>00132         <span class="comment">// mail には、ppe scheduler からの mail がある</span>
<a name="l00133"></a>00133         mail_check(mail);
<a name="l00134"></a>00134 
<a name="l00135"></a>00135         <span class="comment">// 依存関係を満たしたものは実行可能キューへ</span>
<a name="l00136"></a>00136         wakeup_waitTask();
<a name="l00137"></a>00137         list = get_runTaskList();
<a name="l00138"></a>00138     } <span class="keywordflow">while</span> (list);
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00147"></a>00147 MailQueuePtr
<a name="l00148"></a>00148 FifoTaskManagerImpl::schedule(TaskListPtr list)
<a name="l00149"></a>00149 {
<a name="l00150"></a>00150     MailQueuePtr list_mail; <span class="comment">// task list</span>
<a name="l00151"></a>00151     MailQueuePtr sentinel;  <span class="comment">// 番兵</span>
<a name="l00152"></a>00152     MailQueuePtr in_mail_list = NULL;
<a name="l00153"></a>00153     MailQueuePtr out_mail_list = NULL;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155     <span class="comment">// TaskList のアドレス</span>
<a name="l00156"></a>00156     list_mail = mailManager-&gt;create((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)list);
<a name="l00157"></a>00157     in_mail_list = MailManager::append_mailQueue(in_mail_list, list_mail);
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     <span class="comment">// EXIT_COMMAND (番兵的な意味で)</span>
<a name="l00160"></a>00160     sentinel  = mailManager-&gt;create(MY_SPE_COMMAND_EXIT);
<a name="l00161"></a>00161     in_mail_list = MailManager::append_mailQueue(in_mail_list, sentinel);
<a name="l00162"></a>00162     
<a name="l00163"></a>00163     <span class="comment">// scheduler は受け取ったメールを元に実行する</span>
<a name="l00164"></a>00164     scheduler-&gt;send_mailList(in_mail_list);
<a name="l00165"></a>00165     scheduler-&gt;run();
<a name="l00166"></a>00166     out_mail_list = scheduler-&gt;recv_mailList(); 
<a name="l00167"></a>00167 
<a name="l00168"></a>00168     <span class="keywordflow">return</span> out_mail_list;
<a name="l00169"></a>00169 }
<a name="l00170"></a>00170 
<a name="l00181"></a>00181 <span class="keywordtype">void</span>
<a name="l00182"></a>00182 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184     MailQueuePtr q = mail_list;
<a name="l00185"></a>00185     MailQueuePtr d;
<a name="l00186"></a>00186     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188     <span class="keywordflow">while</span> (q) {
<a name="l00189"></a>00189         data = q-&gt;data;
<a name="l00190"></a>00190 
<a name="l00200"></a>00200         <span class="keywordflow">if</span> (data == MY_SPE_STATUS_READY) {
<a name="l00201"></a>00201             __debug_ppe(<span class="stringliteral">"mail_check(): Task List finish\n"</span>);
<a name="l00202"></a>00202         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (data &gt; MY_SPE_NOP) {
<a name="l00203"></a>00203             __debug_ppe(<span class="stringliteral">"mail_check(): recv from 0x%x\n"</span>, data);
<a name="l00204"></a>00204             check_task_finish((HTaskPtr)data);
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         d = q;
<a name="l00208"></a>00208         q = q-&gt;next;
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         mailManager-&gt;free(d);
<a name="l00211"></a>00211     }
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213 
<a name="l00214"></a>00214 <span class="keywordtype">void</span>
<a name="l00215"></a>00215 FifoTaskManagerImpl::mail_check(MailQueuePtr mail_list, TaskQueuePtr *wait)
<a name="l00216"></a>00216 {
<a name="l00217"></a>00217     waitTaskQueue = *wait;
<a name="l00218"></a>00218     mail_check(mail_list);
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 
<a name="l00221"></a>00221 <span class="keywordtype">void</span>*
<a name="l00222"></a>00222 FifoTaskManagerImpl::allocate(<span class="keywordtype">int</span> size)
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224     <span class="keywordflow">return</span> malloc(size);
<a name="l00225"></a>00225 }
<a name="l00226"></a>00226 
<a name="l00232"></a>00232 <span class="preprocessor">#ifdef __CERIUM_FIFO__</span>
<a name="l00233"></a>00233 <span class="preprocessor"></span>TaskManagerImpl* 
<a name="l00234"></a>00234 create_impl(<span class="keywordtype">int</span> num)
<a name="l00235"></a>00235 {
<a name="l00236"></a>00236     <span class="keywordflow">return</span> <span class="keyword">new</span> FifoTaskManagerImpl();
<a name="l00237"></a>00237 }
<a name="l00238"></a>00238 <span class="preprocessor">#endif // __CERIUM_FIFO__</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 5 18:14:06 2009 for Cerium by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.7.1 </small></address>
</body>
</html>