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

📄 a00012.html

📁 Protothreads are extremely lightweight stackless threads designed for severely memory constrained s
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>The Protothreads Library 1.0: Protothreads</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>Protothreads</h1><hr><a name="_details"></a><h2>Detailed Description</h2>Protothreads are implemented in a single header file, <a class="el" href="a00011.html">pt.h</a>, which includes the local continuations header file, <a class="el" href="a00009.html">lc.h</a>. This file in turn includes the actual implementation of local continuations, which typically also is contained in a single header file. <p><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Files</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>file &nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00011.html">pt.h</a></td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Protothreads implementation. <br><br></td></tr><p><tr><td colspan=2><br><h2>Modules</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>group&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00013.html">Protothread semaphores</a></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>group&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00014.html">Local continuations</a></td></tr><tr><td colspan=2><br><h2>Defines</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga2">PT_THREAD</a>(name_args)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Declaration of a protothread.  <a href="#ga2"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga3">PT_INIT</a>(pt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initialize a protothread.  <a href="#ga3"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga4">PT_BEGIN</a>(pt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Declare the start of a protothread inside the C function implementing the protothread.  <a href="#ga4"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(pt, condition)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait until condition is true.  <a href="#ga5"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga6">PT_WAIT_WHILE</a>(pt, cond)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait while condition is true.  <a href="#ga6"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga7">PT_WAIT_THREAD</a>(pt, thread)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait until a child protothread completes.  <a href="#ga7"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga8">PT_SPAWN</a>(pt, thread)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Spawn a child protothread and wait until it exits.  <a href="#ga8"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga9">PT_RESTART</a>(pt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Restart the protothread.  <a href="#ga9"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga10">PT_EXIT</a>(pt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Exit the protothread.  <a href="#ga10"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga11">PT_END</a>(pt)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Declare the end of a protothread.  <a href="#ga11"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a00012.html#ga12">PT_SCHEDULE</a>(f)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Schedule a protothread.  <a href="#ga12"></a><br><br></td></tr></table><hr><h2>Define Documentation</h2><a class="anchor" name="ga4" doxytag="pt.h::PT_BEGIN" ></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_BEGIN</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt&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>Declare the start of a protothread inside the C function implementing the protothread. <p>This macro is used to declare the starting point of a protothread. It should be placed at the start of the function in which the protothread runs. All C statements above the <a class="el" href="a00012.html#ga4">PT_BEGIN()</a> invokation will be executed each time the protothread is scheduled.<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>  </table></dl>Example:<p><pre class="fragment"><div> <a class="code" href="a00012.html#ga2">PT_THREAD</a>(producer(<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 == CONSUMED || event == DROPPED);     produce();     <a class="code" href="a00012.html#ga5">PT_WAIT_UNTIL</a>(event == PRODUCED);   }      <a class="code" href="a00012.html#ga11">PT_END</a>(p); }</div></pre>    </td>  </tr></table><a class="anchor" name="ga11" doxytag="pt.h::PT_END" ></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_END</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt&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>Declare the end of a protothread. <p>This macro is used for declaring that a protothread ends. It should always be used together with a matching <a class="el" href="a00012.html#ga4">PT_BEGIN()</a> macro.<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>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga10" doxytag="pt.h::PT_EXIT" ></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_EXIT</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt&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>Exit the protothread. <p>This macro causes the protothread to exit. If the protothread was spawned by another protothread, the parent protothread will become unblocked and can continue to run.<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>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga3" doxytag="pt.h::PT_INIT" ></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_INIT</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt&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>Initialize a protothread. <p>Initializes a protothread. Initialization must be done prior to starting to execute the 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>  </table></dl>Example:<p><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>    </td>  </tr></table><a class="anchor" name="ga9" doxytag="pt.h::PT_RESTART" ></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_RESTART</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">pt&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>Restart the protothread. <p>This macro will block and cause the running protothread to restart its execution at the place of the <a class="el" href="a00012.html#ga4">PT_BEGIN()</a> call.<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>  </table></dl>    </td>  </tr></table><a class="anchor" name="ga12" doxytag="pt.h::PT_SCHEDULE" ></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_SCHEDULE</td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">f&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap>      </table>

⌨️ 快捷键说明

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