⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a00019.html

📁 Protothreads are extremely lightweight stackless threads designed for severely memory constrained s
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00165 <span class="comment">   PT_WAIT_UNTIL(p, time &gt;= 2 * SECOND);</span>00166 <span class="comment">   printf("Two seconds have passed\n");</span>00167 <span class="comment">   </span>00168 <span class="comment">   PT_END(p);</span>00169 <span class="comment"> }</span>00170 <span class="comment"> \endcode</span>00171 <span class="comment"> *</span>00172 <span class="comment"> * \hideinitializer</span>00173 <span class="comment"> */</span><a name="l00174"></a><a class="code" href="a00012.html#ga5">00174</a> <span class="preprocessor">#define PT_WAIT_UNTIL(pt, condition)            \</span>00175 <span class="preprocessor">  do {                                          \</span>00176 <span class="preprocessor">    LC_SET((pt)-&gt;lc);                           \</span>00177 <span class="preprocessor">    if(!(condition)) {                          \</span>00178 <span class="preprocessor">      return PT_THREAD_WAITING;                 \</span>00179 <span class="preprocessor">    }                                           \</span>00180 <span class="preprocessor">  } while(0)</span>00181 <span class="preprocessor"></span><span class="comment"></span>00182 <span class="comment">/**</span>00183 <span class="comment"> * Block and wait while condition is true.</span>00184 <span class="comment"> *</span>00185 <span class="comment"> * This function blocks and waits while condition is true. See</span>00186 <span class="comment"> * PT_WAIT_UNTIL().</span>00187 <span class="comment"> *</span>00188 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00189 <span class="comment"> * \param cond The condition.</span>00190 <span class="comment"> *</span>00191 <span class="comment"> * \hideinitializer</span>00192 <span class="comment"> */</span><a name="l00193"></a><a class="code" href="a00012.html#ga6">00193</a> <span class="preprocessor">#define PT_WAIT_WHILE(pt, cond)                 \</span>00194 <span class="preprocessor">  PT_WAIT_UNTIL((pt), !(cond))</span>00195 <span class="preprocessor"></span>00196 <span class="comment"></span>00197 <span class="comment">/**</span>00198 <span class="comment"> * Block and wait until a child protothread completes.</span>00199 <span class="comment"> *</span>00200 <span class="comment"> * This macro schedules a child protothread. The current protothread</span>00201 <span class="comment"> * will block until the child protothread completes.</span>00202 <span class="comment"> *</span>00203 <span class="comment"> * \note The child protothread must be manually initialized with the</span>00204 <span class="comment"> * PT_INIT() function before this function is used.</span>00205 <span class="comment"> *</span>00206 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00207 <span class="comment"> * \param thread The child protothread with arguments</span>00208 <span class="comment"> *</span>00209 <span class="comment"> * Example:</span>00210 <span class="comment"> \code</span>00211 <span class="comment"> PT_THREAD(child(struct pt *p, int event)) {</span>00212 <span class="comment">   PT_BEGIN(p);</span>00213 <span class="comment"></span>00214 <span class="comment">   PT_WAIT_UNTIL(event == EVENT1);   </span>00215 <span class="comment">   </span>00216 <span class="comment">   PT_END(p);</span>00217 <span class="comment"> }</span>00218 <span class="comment"></span>00219 <span class="comment"> PT_THREAD(parent(struct pt *p, struct pt *child_pt, int event)) {</span>00220 <span class="comment">   PT_BEGIN(p);</span>00221 <span class="comment"></span>00222 <span class="comment">   PT_INIT(child_pt);</span>00223 <span class="comment">   </span>00224 <span class="comment">   PT_WAIT_THREAD(p, child(child_pt, event));</span>00225 <span class="comment">   </span>00226 <span class="comment">   PT_END(p);</span>00227 <span class="comment"> }</span>00228 <span class="comment"> \endcode</span>00229 <span class="comment"> *</span>00230 <span class="comment"> * \hideinitializer </span>00231 <span class="comment"> */</span><a name="l00232"></a><a class="code" href="a00012.html#ga7">00232</a> <span class="preprocessor">#define PT_WAIT_THREAD(pt, thread)              \</span>00233 <span class="preprocessor">  PT_WAIT_UNTIL((pt), (thread))</span>00234 <span class="preprocessor"></span><span class="comment"></span>00235 <span class="comment">/**</span>00236 <span class="comment"> * Spawn a child protothread and wait until it exits.</span>00237 <span class="comment"> *</span>00238 <span class="comment"> * This macro spawns a child protothread and waits until it exits. The</span>00239 <span class="comment"> * macro can only be used within a protothread.</span>00240 <span class="comment"> *</span>00241 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00242 <span class="comment"> * \param thread The child protothread with arguments</span>00243 <span class="comment"> *</span>00244 <span class="comment"> * \hideinitializer</span>00245 <span class="comment"> */</span><a name="l00246"></a><a class="code" href="a00012.html#ga8">00246</a> <span class="preprocessor">#define PT_SPAWN(pt, thread)                    \</span>00247 <span class="preprocessor">  do {                                          \</span>00248 <span class="preprocessor">    PT_INIT((pt));                              \</span>00249 <span class="preprocessor">    PT_WAIT_THREAD((pt), (thread));             \</span>00250 <span class="preprocessor">  } while(0)</span>00251 <span class="preprocessor"></span><span class="comment"></span>00252 <span class="comment">/**</span>00253 <span class="comment"> * Restart the protothread.</span>00254 <span class="comment"> *</span>00255 <span class="comment"> * This macro will block and cause the running protothread to restart</span>00256 <span class="comment"> * its execution at the place of the PT_BEGIN() call.</span>00257 <span class="comment"> *</span>00258 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00259 <span class="comment"> *</span>00260 <span class="comment"> * \hideinitializer</span>00261 <span class="comment"> */</span><a name="l00262"></a><a class="code" href="a00012.html#ga9">00262</a> <span class="preprocessor">#define PT_RESTART(pt)                          \</span>00263 <span class="preprocessor">  do {                                          \</span>00264 <span class="preprocessor">    PT_INIT(pt);                                \</span>00265 <span class="preprocessor">    return PT_THREAD_WAITING;                   \</span>00266 <span class="preprocessor">  } while(0)</span>00267 <span class="preprocessor"></span><span class="comment"></span>00268 <span class="comment">/**</span>00269 <span class="comment"> * Exit the protothread.</span>00270 <span class="comment"> *</span>00271 <span class="comment"> * This macro causes the protothread to exit. If the protothread was</span>00272 <span class="comment"> * spawned by another protothread, the parent protothread will become</span>00273 <span class="comment"> * unblocked and can continue to run.</span>00274 <span class="comment"> *</span>00275 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00276 <span class="comment"> *</span>00277 <span class="comment"> * \hideinitializer</span>00278 <span class="comment"> */</span><a name="l00279"></a><a class="code" href="a00012.html#ga10">00279</a> <span class="preprocessor">#define PT_EXIT(pt)                             \</span>00280 <span class="preprocessor">  do {                                          \</span>00281 <span class="preprocessor">    PT_INIT(pt);                                \</span>00282 <span class="preprocessor">    return PT_THREAD_EXITED;                    \</span>00283 <span class="preprocessor">  } while(0)</span>00284 <span class="preprocessor"></span><span class="comment"></span>00285 <span class="comment">/**</span>00286 <span class="comment"> * Declare the end of a protothread.</span>00287 <span class="comment"> *</span>00288 <span class="comment"> * This macro is used for declaring that a protothread ends. It should</span>00289 <span class="comment"> * always be used together with a matching PT_BEGIN() macro.</span>00290 <span class="comment"> *</span>00291 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>00292 <span class="comment"> *</span>00293 <span class="comment"> * \hideinitializer</span>00294 <span class="comment"> */</span><a name="l00295"></a><a class="code" href="a00012.html#ga11">00295</a> <span class="preprocessor">#define PT_END(pt) LC_END((pt)-&gt;lc); PT_EXIT(pt)</span>00296 <span class="preprocessor"></span>00297 <span class="comment"></span>00298 <span class="comment">/**</span>00299 <span class="comment"> * Schedule a protothread.</span>00300 <span class="comment"> *</span>00301 <span class="comment"> * This function shedules a protothread. The return value of the</span>00302 <span class="comment"> * function is non-zero if the protothread is running or zero if the</span>00303 <span class="comment"> * protothread has exited.</span>00304 <span class="comment"> *</span>00305 <span class="comment"> * Example</span>00306 <span class="comment"> \code</span>00307 <span class="comment"> void main(void) {</span>00308 <span class="comment">   struct pt p;</span>00309 <span class="comment">   int event;</span>00310 <span class="comment">   </span>00311 <span class="comment">   PT_INIT(&amp;p);</span>00312 <span class="comment">   while(PT_SCHEDULE(consumer(&amp;p, event))) {</span>00313 <span class="comment">     event = get_event();</span>00314 <span class="comment">   }   </span>00315 <span class="comment"> }</span>00316 <span class="comment"> \endcode</span>00317 <span class="comment"> *</span>00318 <span class="comment"> * \param f The call to the C function implementing the protothread to</span>00319 <span class="comment"> * be scheduled</span>00320 <span class="comment"> *</span>00321 <span class="comment"> * \hideinitializer</span>00322 <span class="comment"> */</span><a name="l00323"></a><a class="code" href="a00012.html#ga12">00323</a> <span class="preprocessor">#define PT_SCHEDULE(f) (f == PT_THREAD_WAITING)</span>00324 <span class="preprocessor"></span>00325 <span class="preprocessor">#endif </span><span class="comment">/* __PT_H__ */</span>00326 00327 <span class="comment"></span>00328 <span class="comment">/** @} */</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Feb 24 11:39:16 2005 for The Protothreads Library 1.0 by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -