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

📄 a00012.html

📁 Protothreads are extremely lightweight stackless threads designed for severely memory constrained s
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Schedule a protothread. <p>This function shedules a protothread. The return value of the function is non-zero if the protothread is running or zero if the protothread has exited.<p>Example <pre class="fragment"><div> <span class="keywordtype">void</span> main(<span class="keywordtype">void</span>) {   <span class="keyword">struct </span>pt p;   <span class="keywordtype">int</span> event;      <a class="code" href="a00012.html#ga3">PT_INIT</a>(&amp;p);   <span class="keywordflow">while</span>(<a class="code" href="a00012.html#ga12">PT_SCHEDULE</a>(consumer(&amp;p, event))) {     event = get_event();   }    }</div></pre><p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>f</em>&nbsp;</td><td>The call to the C function implementing the protothread to be scheduled </td></tr>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga8" doxytag="pt.h::PT_SPAWN" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define PT_SPAWN</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt,         <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>thread&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Spawn a child protothread and wait until it exits. <p>This macro spawns a child protothread and waits until it exits. The macro can only be used within a protothread.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>    <tr><td valign=top><em>thread</em>&nbsp;</td><td>The child protothread with arguments </td></tr>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga2" doxytag="pt.h::PT_THREAD" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define PT_THREAD</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">name_args&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Declaration of a protothread. <p>This macro is used to declare a protothread. All protothreads must be declared with this macro.<p>Example: <pre class="fragment"><div> <a class="code" href="a00012.html#ga2">PT_THREAD</a>(consumer(<span class="keyword">struct</span> pt *p, <span class="keywordtype">int</span> event)) {   <a class="code" href="a00012.html#ga4">PT_BEGIN</a>(p);   <span class="keywordflow">while</span>(1) {     <a class="code" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(event == AVAILABLE);     consume();     <a class="code" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(event == CONSUMED);     acknowledge_consumed();   }   <a class="code" href="a00012.html#ga11">PT_END</a>(p); }</div></pre><p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>name_args</em>&nbsp;</td><td>The name and arguments of the C function implementing the protothread. </td></tr>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga7" doxytag="pt.h::PT_WAIT_THREAD" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define PT_WAIT_THREAD</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt,         <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>thread&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Block and wait until a child protothread completes. <p>This macro schedules a child protothread. The current protothread will block until the child protothread completes.<p><dl compact><dt><b>Note:</b></dt><dd>The child protothread must be manually initialized with the <a class="el" href="a00012.html#ga3">PT_INIT()</a> function before this function is used.</dd></dl><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>    <tr><td valign=top><em>thread</em>&nbsp;</td><td>The child protothread with arguments</td></tr>  </table></dl>Example: <pre class="fragment"><div> <a class="code" href="a00012.html#ga2">PT_THREAD</a>(child(<span class="keyword">struct</span> pt *p, <span class="keywordtype">int</span> event)) {   <a class="code" href="a00012.html#ga4">PT_BEGIN</a>(p);   <a class="code" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(event == EVENT1);         <a class="code" href="a00012.html#ga11">PT_END</a>(p); } <a class="code" href="a00012.html#ga2">PT_THREAD</a>(parent(<span class="keyword">struct</span> pt *p, <span class="keyword">struct</span> pt *child_pt, <span class="keywordtype">int</span> event)) {   <a class="code" href="a00012.html#ga4">PT_BEGIN</a>(p);   <a class="code" href="a00012.html#ga3">PT_INIT</a>(child_pt);      <a class="code" href="a00012.html#ga7">PT_WAIT_THREAD</a>(p, child(child_pt, event));      <a class="code" href="a00012.html#ga11">PT_END</a>(p); }</div></pre>    </td>  </tr></table><a class="anchor" name="ga5" doxytag="pt.h::PT_WAIT_UNTIL" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define PT_WAIT_UNTIL</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt,         <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>condition&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Block and wait until condition is true. <p>This macro blocks the protothread until the specified condition is true.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>    <tr><td valign=top><em>condition</em>&nbsp;</td><td>The condition.</td></tr>  </table></dl>Example: <pre class="fragment"><div> <a class="code" href="a00012.html#ga2">PT_THREAD</a>(seconds(<span class="keyword">struct</span> pt *p)) {   <a class="code" href="a00012.html#ga4">PT_BEGIN</a>(p);   <a class="code" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(p, time &gt;= 2 * SECOND);   printf(<span class="stringliteral">"Two seconds have passed\n"</span>);      <a class="code" href="a00012.html#ga11">PT_END</a>(p); }</div></pre>    </td>  </tr></table><a class="anchor" name="ga6" doxytag="pt.h::PT_WAIT_WHILE" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define PT_WAIT_WHILE</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt,         <tr>          <td class="md" nowrap align="right"></td>          <td></td>          <td class="md" nowrap>cond&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Block and wait while condition is true. <p>This function blocks and waits while condition is true. See <a class="el" href="a00012.html#ga5">PT_WAIT_UNTIL()</a>.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign=top><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>    <tr><td valign=top><em>cond</em>&nbsp;</td><td>The condition. </td></tr>  </table></dl>    </td>  </tr></table><hr size="1"><address style="align: right;"><small>Generated on Thu Feb 24 11:39:17 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 + -