rtt-f030/components/net/uip/doc/html/a00142.html

691 lines
38 KiB
HTML
Raw Normal View History

<!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>uIP 1.0: Protothreads</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.4.6 -->
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul></div>
<h1>Protothreads</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
Protothreads are a type of lightweight stackless threads designed for severly memory constrained systems such as deeply embedded systems or sensor network nodes.
<p>
Protothreads provides linear code execution for event-driven systems implemented in C. Protothreads can be used with or without an RTOS.<p>
Protothreads are a extremely lightweight, stackless type of threads that provides a blocking context on top of an event-driven system, without the overhead of per-thread stacks. The purpose of protothreads is to implement sequential flow of control without complex state machines or full multi-threading. Protothreads provides conditional blocking inside C functions.<p>
The advantage of protothreads over a purely event-driven approach is that protothreads provides a sequential code structure that allows for blocking functions. In purely event-driven systems, blocking must be implemented by manually breaking the function into two pieces - one for the piece of code before the blocking call and one for the code after the blocking call. This makes it hard to use control structures such as if() conditionals and while() loops.<p>
The advantage of protothreads over ordinary threads is that a protothread do not require a separate stack. In memory constrained systems, the overhead of allocating multiple stacks can consume large amounts of the available memory. In contrast, each protothread only requires between two and twelve bytes of state, depending on the architecture.<p>
<dl compact><dt><b>Note:</b></dt><dd>Because protothreads do not save the stack context across a blocking call, <b>local variables are not preserved when the protothread blocks</b>. This means that local variables should be used with utmost care - <b>if in doubt, do not use local variables inside a protothread!</b></dd></dl>
Main features:<p>
<ul>
<li>No machine specific code - the protothreads library is pure C</li></ul>
<p>
<ul>
<li>Does not use error-prone functions such as longjmp()</li></ul>
<p>
<ul>
<li>Very small RAM overhead - only two bytes per protothread</li></ul>
<p>
<ul>
<li>Can be used with or without an OS</li></ul>
<p>
<ul>
<li>Provides blocking wait without full multi-threading or stack-switching</li></ul>
<p>
Examples applications:<p>
<ul>
<li>Memory constrained systems</li></ul>
<p>
<ul>
<li>Event-driven protocol stacks</li></ul>
<p>
<ul>
<li>Deeply embedded systems</li></ul>
<p>
<ul>
<li>Sensor network nodes</li></ul>
<p>
The protothreads API consists of four basic operations: initialization: <a class="el" href="a00142.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT()</a>, execution: <a class="el" href="a00142.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN()</a>, conditional blocking: <a class="el" href="a00142.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL()</a> and exit: <a class="el" href="a00142.html#g7b04a0035bef29d905496c23bae066d2">PT_END()</a>. On top of these, two convenience functions are built: reversed condition blocking: <a class="el" href="a00142.html#gad14bbbf092b90aa0a5a4f9169504a8d">PT_WAIT_WHILE()</a> and protothread blocking: <a class="el" href="a00142.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD()</a>.<p>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00142.html">Protothreads API documentation</a></dd></dl>
The protothreads library is released under a BSD-style license that allows for both non-commercial and commercial usage. The only requirement is that credit is given.<h2><a class="anchor" name="authors">
Authors</a></h2>
The protothreads library was written by Adam Dunkels &lt;<a href="mailto:adam@sics.se">adam@sics.se</a>&gt; with support from Oliver Schmidt &lt;<a href="mailto:ol.sc@web.de">ol.sc@web.de</a>&gt;.<h2><a class="anchor" name="pt-desc">
Protothreads</a></h2>
Protothreads are a extremely lightweight, stackless threads that provides a blocking context on top of an event-driven system, without the overhead of per-thread stacks. The purpose of protothreads is to implement sequential flow of control without using complex state machines or full multi-threading. Protothreads provides conditional blocking inside a C function.<p>
In memory constrained systems, such as deeply embedded systems, traditional multi-threading may have a too large memory overhead. In traditional multi-threading, each thread requires its own stack, that typically is over-provisioned. The stacks may use large parts of the available memory.<p>
The main advantage of protothreads over ordinary threads is that protothreads are very lightweight: a protothread does not require its own stack. Rather, all protothreads run on the same stack and context switching is done by stack rewinding. This is advantageous in memory constrained systems, where a stack for a thread might use a large part of the available memory. A protothread only requires only two bytes of memory per protothread. Moreover, protothreads are implemented in pure C and do not require any machine-specific assembler code.<p>
A protothread runs within a single C function and cannot span over other functions. A protothread may call normal C functions, but cannot block inside a called function. Blocking inside nested function calls is instead made by spawning a separate protothread for each potentially blocking function. The advantage of this approach is that blocking is explicit: the programmer knows exactly which functions that block that which functions the never blocks.<p>
Protothreads are similar to asymmetric co-routines. The main difference is that co-routines uses a separate stack for each co-routine, whereas protothreads are stackless. The most similar mechanism to protothreads are Python generators. These are also stackless constructs, but have a different purpose. Protothreads provides blocking contexts inside a C function, whereas Python generators provide multiple exit points from a generator function.<h2><a class="anchor" name="pt-autovars">
Local variables</a></h2>
<dl compact><dt><b>Note:</b></dt><dd>Because protothreads do not save the stack context across a blocking call, local variables are not preserved when the protothread blocks. This means that local variables should be used with utmost care - if in doubt, do not use local variables inside a protothread!</dd></dl>
<h2><a class="anchor" name="pt-scheduling">
Scheduling</a></h2>
A protothread is driven by repeated calls to the function in which the protothread is running. Each time the function is called, the protothread will run until it blocks or exits. Thus the scheduling of protothreads is done by the application that uses protothreads.<h2><a class="anchor" name="pt-impl">
Implementation</a></h2>
Protothreads are implemented using <a class="el" href="a00155.html">local continuations</a>. A local continuation represents the current state of execution at a particular place in the program, but does not provide any call history or local variables. A local continuation can be set in a specific function to capture the state of the function. After a local continuation has been set can be resumed in order to restore the state of the function at the point where the local continuation was set.<p>
Local continuations can be implemented in a variety of ways:<p>
<ol type=1>
<li>by using machine specific assembler code,</li><li>by using standard C constructs, or</li><li>by using compiler extensions.</li></ol>
<p>
The first way works by saving and restoring the processor state, except for stack pointers, and requires between 16 and 32 bytes of memory per protothread. The exact amount of memory required depends on the architecture.<p>
The standard C implementation requires only two bytes of state per protothread and utilizes the C switch() statement in a non-obvious way that is similar to Duff's device. This implementation does, however, impose a slight restriction to the code that uses protothreads in that the code cannot use switch() statements itself.<p>
Certain compilers has C extensions that can be used to implement protothreads. GCC supports label pointers that can be used for this purpose. With this implementation, protothreads require 4 bytes of RAM per protothread.
<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="a00128.html">pt.h</a></td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Protothreads implementation. <br></td></tr>
<p>
<tr><td colspan="2"><br><h2>Modules</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00155.html">Local continuations</a></td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Local continuations form the basis for implementing protothreads. <br></td></tr>
<p>
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00084.html">pt</a></td></tr>
<tr><td colspan="2"><br><h2>Initialization</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(<a class="el" href="a00084.html">pt</a>)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initialize a protothread. <a href="#ge6bae7dc0225468c8a5ac269df549892"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Declaration and definition</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(name_args)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Declaration of a protothread. <a href="#g3d4c8bd4aada659eb34f5d2ffd3e7901"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(<a class="el" href="a00084.html">pt</a>)</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="#g2ffbb9e554e08a343ae2f9de4bedfdfc"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(<a class="el" href="a00084.html">pt</a>)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Declare the end of a protothread. <a href="#g7b04a0035bef29d905496c23bae066d2"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Blocked wait</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(<a class="el" href="a00084.html">pt</a>, condition)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait until condition is true. <a href="#g99e43010ec61327164466aa2d902de45"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#gad14bbbf092b90aa0a5a4f9169504a8d">PT_WAIT_WHILE</a>(<a class="el" href="a00084.html">pt</a>, cond)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait while condition is true. <a href="#gad14bbbf092b90aa0a5a4f9169504a8d"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Hierarchical protothreads</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD</a>(<a class="el" href="a00084.html">pt</a>, thread)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Block and wait until a child protothread completes. <a href="#g2f8f70c30b9ee08a103fbd69a4365c4c"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN</a>(<a class="el" href="a00084.html">pt</a>, child, thread)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Spawn a child protothread and wait until it exits. <a href="#g9e97a0b4d5cc7764d8e19758f5da53ae"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Exiting and restarting</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">PT_RESTART</a>(<a class="el" href="a00084.html">pt</a>)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Restart the protothread. <a href="#gcd3ac045f0a4ae63412e3b3d8780e8ab"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g905451249dca72ce0385bf2a9ff178ee">PT_EXIT</a>(<a class="el" href="a00084.html">pt</a>)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Exit the protothread. <a href="#g905451249dca72ce0385bf2a9ff178ee"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Calling a protothread</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(f)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Schedule a protothread. <a href="#gfa82b860a64b67d25ab3abc21811896f"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Yielding from a protothread</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g155cba6121323726d02c00284428fed6">PT_YIELD</a>(<a class="el" href="a00084.html">pt</a>)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Yield from the current protothread. <a href="#g155cba6121323726d02c00284428fed6"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#ge3c821e3a388615528efda9d23c7d115">PT_YIELD_UNTIL</a>(<a class="el" href="a00084.html">pt</a>, cond)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Yield from the protothread until a condition occurs. <a href="#ge3c821e3a388615528efda9d23c7d115"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g7b5319b5b65761a845fcd1500fde4cdc"></a><!-- doxytag: member="pt::PT_WAITING" ref="g7b5319b5b65761a845fcd1500fde4cdc" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g7b5319b5b65761a845fcd1500fde4cdc">PT_WAITING</a>&nbsp;&nbsp;&nbsp;0</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gcfae9053e5c107a1aed6b228c917d2ea"></a><!-- doxytag: member="pt::PT_EXITED" ref="gcfae9053e5c107a1aed6b228c917d2ea" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#gcfae9053e5c107a1aed6b228c917d2ea">PT_EXITED</a>&nbsp;&nbsp;&nbsp;1</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g9ff1e8936a8a26bff54c05f8a989b93b"></a><!-- doxytag: member="pt::PT_ENDED" ref="g9ff1e8936a8a26bff54c05f8a989b93b" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#g9ff1e8936a8a26bff54c05f8a989b93b">PT_ENDED</a>&nbsp;&nbsp;&nbsp;2</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ge469332907e0617d72d5e2dd4297119d"></a><!-- doxytag: member="pt::PT_YIELDED" ref="ge469332907e0617d72d5e2dd4297119d" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00142.html#ge469332907e0617d72d5e2dd4297119d">PT_YIELDED</a>&nbsp;&nbsp;&nbsp;3</td></tr>
</table>
<hr><h2>Define Documentation</h2>
<a class="anchor" name="g2ffbb9e554e08a343ae2f9de4bedfdfc"></a><!-- doxytag: member="pt.h::PT_BEGIN" ref="g2ffbb9e554e08a343ae2f9de4bedfdfc" args="(pt)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</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="a00142.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
</table>
</dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a17">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00115">115</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g7b04a0035bef29d905496c23bae066d2"></a><!-- doxytag: member="pt.h::PT_END" ref="g7b04a0035bef29d905496c23bae066d2" args="(pt)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</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 must always be used together with a matching <a class="el" href="a00142.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN()</a> macro.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
</table>
</dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a34">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00127">127</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g905451249dca72ce0385bf2a9ff178ee"></a><!-- doxytag: member="pt.h::PT_EXIT" ref="g905451249dca72ce0385bf2a9ff178ee" args="(pt)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
</table>
</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00246">246</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="ge6bae7dc0225468c8a5ac269df549892"></a><!-- doxytag: member="pt.h::PT_INIT" ref="ge6bae7dc0225468c8a5ac269df549892" args="(pt)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure.</td></tr>
</table>
</dl>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00142.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN()</a> </dd></dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a41">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00080">80</a> of file <a class="el" href="a00194.html">pt.h</a>.
<p>
Referenced by <a class="el" href="a00184.html#l00298">httpd_appcall()</a>. </td>
</tr>
</table>
<a class="anchor" name="gcd3ac045f0a4ae63412e3b3d8780e8ab"></a><!-- doxytag: member="pt.h::PT_RESTART" ref="gcd3ac045f0a4ae63412e3b3d8780e8ab" args="(pt)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</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="a00142.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN()</a> call.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
</table>
</dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a27">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00229">229</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="gfa82b860a64b67d25ab3abc21811896f"></a><!-- doxytag: member="pt.h::PT_SCHEDULE" ref="gfa82b860a64b67d25ab3abc21811896f" args="(f)" --><p>
<table class="mdTable" 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></td>
</tr>
</table>
</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>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><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>
<p>
Definition at line <a class="el" href="a00194.html#l00271">271</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g9e97a0b4d5cc7764d8e19758f5da53ae"></a><!-- doxytag: member="pt.h::PT_SPAWN" ref="g9e97a0b4d5cc7764d8e19758f5da53ae" args="(pt, child, thread)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></td>
<td class="md" nowrap>child, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></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></td>
</tr>
</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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>child</em>&nbsp;</td><td>A pointer to the child protothread's control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>thread</em>&nbsp;</td><td>The child protothread with arguments </td></tr>
</table>
</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00206">206</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g3d4c8bd4aada659eb34f5d2ffd3e7901"></a><!-- doxytag: member="pt.h::PT_THREAD" ref="g3d4c8bd4aada659eb34f5d2ffd3e7901" args="(name_args)" --><p>
<table class="mdTable" 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></td>
</tr>
</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>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><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>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a16">dhcpc.c</a>, and <a class="el" href="a00038.html#a165">smtp.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00100">100</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g2f8f70c30b9ee08a103fbd69a4365c4c"></a><!-- doxytag: member="pt.h::PT_WAIT_THREAD" ref="g2f8f70c30b9ee08a103fbd69a4365c4c" args="(pt, thread)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></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></td>
</tr>
</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="a00142.html#ge6bae7dc0225468c8a5ac269df549892">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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>thread</em>&nbsp;</td><td>The child protothread with arguments</td></tr>
</table>
</dl>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00142.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN()</a> </dd></dl>
<p>
Definition at line <a class="el" href="a00194.html#l00192">192</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g99e43010ec61327164466aa2d902de45"></a><!-- doxytag: member="pt.h::PT_WAIT_UNTIL" ref="g99e43010ec61327164466aa2d902de45" args="(pt, condition)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></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></td>
</tr>
</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"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>condition</em>&nbsp;</td><td>The condition. </td></tr>
</table>
</dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a24">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00148">148</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="gad14bbbf092b90aa0a5a4f9169504a8d"></a><!-- doxytag: member="pt.h::PT_WAIT_WHILE" ref="gad14bbbf092b90aa0a5a4f9169504a8d" args="(pt, cond)" --><p>
<table class="mdTable" 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"><a class="el" href="a00084.html">pt</a>, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></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></td>
</tr>
</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="a00142.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL()</a>.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>cond</em>&nbsp;</td><td>The condition. </td></tr>
</table>
</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00167">167</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="g155cba6121323726d02c00284428fed6"></a><!-- doxytag: member="pt.h::PT_YIELD" ref="g155cba6121323726d02c00284428fed6" args="(pt)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">#define PT_YIELD </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top"><a class="el" href="a00084.html">pt</a>&nbsp;</td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Yield from the current protothread.
<p>
This function will yield the protothread, thereby allowing other processing to take place in the system.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
</table>
</dl>
<dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="a00048.html#a33">dhcpc.c</a>.</dl>
<p>
Definition at line <a class="el" href="a00194.html#l00290">290</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<a class="anchor" name="ge3c821e3a388615528efda9d23c7d115"></a><!-- doxytag: member="pt.h::PT_YIELD_UNTIL" ref="ge3c821e3a388615528efda9d23c7d115" args="(pt, cond)" --><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">#define PT_YIELD_UNTIL </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top"><a class="el" href="a00084.html">pt</a>, <tr>
<td class="md" nowrap align="right"></td>
<td class="md"></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></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Yield from the protothread until a condition occurs.
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pt</em>&nbsp;</td><td>A pointer to the protothread control structure. </td></tr>
<tr><td valign="top"></td><td valign="top"><em>cond</em>&nbsp;</td><td>The condition.</td></tr>
</table>
</dl>
This function will yield the protothread, until the specified condition evaluates to true.
<p>
Definition at line <a class="el" href="a00194.html#l00310">310</a> of file <a class="el" href="a00194.html">pt.h</a>. </td>
</tr>
</table>
<hr size="1"><address style="align: right;"><small>Generated on Mon Jun 12 10:23:02 2006 for uIP 1.0 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
</body>
</html>