|
@ -0,0 +1,9 @@
|
|||
CFLAGS=-O -Wuninitialized -Werror
|
||||
|
||||
all: example-codelock example-buffer example-small
|
||||
|
||||
example-codelock: example-codelock.c pt.h lc.h
|
||||
|
||||
example-buffer: example-buffer.c pt.h lc.h
|
||||
|
||||
example-small: example-small.c pt.h lc.h
|
|
@ -0,0 +1,5 @@
|
|||
Protothreads can in some cases fail to compile under Visual C++
|
||||
version 6.0 due to a bug in the compiler. See the following page for a
|
||||
solution to the problem:
|
||||
|
||||
http://support.microsoft.com/default.aspx?scid=kb;en-us;199057
|
|
@ -0,0 +1,51 @@
|
|||
Protothreads are extremely lightweight stackless threads designed for
|
||||
severely memory constrained systems such as small embedded systems or
|
||||
sensor network nodes. Protothreads can be used with or without an
|
||||
underlying operating system.
|
||||
|
||||
Protothreads 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.
|
||||
|
||||
Main features:
|
||||
|
||||
* No machine specific code - the protothreads library is pure C
|
||||
* Does not use error-prone functions such as longjmp()
|
||||
* Very small RAM overhead - only two bytes per protothread
|
||||
* Can be used with or without an OS
|
||||
* Provides blocking wait without full multi-threading or
|
||||
stack-switching
|
||||
* Freely available under a BSD-like open source license
|
||||
|
||||
Example applications:
|
||||
|
||||
* Memory constrained systems
|
||||
* Event-driven protocol stacks
|
||||
* Small embedded systems
|
||||
* Sensor network nodes
|
||||
|
||||
The protothreads library is released under an open source BSD-style
|
||||
license that allows for both non-commercial and commercial usage. The
|
||||
only requirement is that credit is given.
|
||||
|
||||
The protothreads library was written by Adam Dunkels <adam@sics.se>
|
||||
with support from Oliver Schmidt <ol.sc@web.de>.
|
||||
|
||||
More information and new versions can be found at the protothreads
|
||||
homepage:
|
||||
http://www.sics.se/~adam/pt/
|
||||
|
||||
Documentation can be found in the doc/ subdirectory.
|
||||
|
||||
Two example programs illustrating the use of protothreads can be found
|
||||
in this directory:
|
||||
|
||||
example-small.c A small example showing how to use protothreads
|
||||
example-buffer.c The bounded buffer problem with protothreads
|
||||
example-codelock.c A code lock with simulated key input
|
||||
|
||||
To compile the examples, simply run "make".
|
||||
|
||||
|
||||
Adam Dunkels, 3 June 2006
|
|
@ -0,0 +1,229 @@
|
|||
# Doxyfile 1.4.6
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
PROJECT_NAME = "The Protothreads Library 1.4"
|
||||
PROJECT_NUMBER =
|
||||
OUTPUT_DIRECTORY = .
|
||||
CREATE_SUBDIRS = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
USE_WINDOWS_ENCODING = NO
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF =
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = YES
|
||||
STRIP_FROM_PATH = ../
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = YES
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
DETAILS_AT_TOP = YES
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 8
|
||||
ALIASES =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
SUBGROUPING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = NO
|
||||
EXTRACT_PRIVATE = NO
|
||||
EXTRACT_STATIC = NO
|
||||
EXTRACT_LOCAL_CLASSES = NO
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
HIDE_UNDOC_MEMBERS = YES
|
||||
HIDE_UNDOC_CLASSES = YES
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_BY_SCOPE_NAME = NO
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = NO
|
||||
GENERATE_DEPRECATEDLIST= NO
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = NO
|
||||
SHOW_DIRECTORIES = NO
|
||||
FILE_VERSION_FILTER =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = pt-mainpage.txt \
|
||||
pt-doc.txt \
|
||||
../pt.h \
|
||||
../pt-sem.h \
|
||||
../lc.h \
|
||||
../lc-switch.h \
|
||||
../lc-addrlabels.h
|
||||
FILE_PATTERNS =
|
||||
RECURSIVE = NO
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXAMPLE_PATH = ..
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = YES
|
||||
STRIP_CODE_COMMENTS = NO
|
||||
REFERENCED_BY_RELATION = YES
|
||||
REFERENCES_RELATION = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = NO
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
GENERATE_HTMLHELP = YES
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
DISABLE_INDEX = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = YES
|
||||
TREEVIEW_WIDTH = 250
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = YES
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
COMPACT_LATEX = YES
|
||||
PAPER_TYPE = a4
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER = header.tex
|
||||
PDF_HYPERLINKS = YES
|
||||
USE_PDFLATEX = YES
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT = rtf
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = NO
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_LINKS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_SCHEMA =
|
||||
XML_DTD =
|
||||
XML_PROGRAMLISTING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options for the AutoGen Definitions output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_PERLMOD = NO
|
||||
PERLMOD_LATEX = NO
|
||||
PERLMOD_PRETTY = YES
|
||||
PERLMOD_MAKEVAR_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED = DOXYGEN
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
PERL_PATH = /usr/bin/perl
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = NO
|
||||
HIDE_UNDOC_RELATIONS = NO
|
||||
HAVE_DOT = NO
|
||||
CLASS_GRAPH = NO
|
||||
COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
UML_LOOK = NO
|
||||
TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = NO
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = YES
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DIRECTORY_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
MAX_DOT_GRAPH_WIDTH = 1024
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
MAX_DOT_GRAPH_DEPTH = 0
|
||||
DOT_TRANSPARENT = NO
|
||||
DOT_MULTI_TARGETS = NO
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
|
@ -0,0 +1,7 @@
|
|||
dox:
|
||||
doxygen Doxyfile
|
||||
|
||||
|
||||
pdf: dox
|
||||
(cd latex; $(MAKE) refman.pdf)
|
||||
mv latex/refman.pdf pt-refman.pdf
|
|
@ -0,0 +1,52 @@
|
|||
\documentclass[a4paper]{article}
|
||||
\usepackage{a4wide}
|
||||
\usepackage{makeidx}
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{multicol}
|
||||
\usepackage{float}
|
||||
\usepackage{textcomp}
|
||||
\usepackage{alltt}
|
||||
\usepackage{times}
|
||||
\usepackage{epsfig}
|
||||
\ifx\pdfoutput\undefined
|
||||
\usepackage[ps2pdf,
|
||||
pagebackref=true,
|
||||
colorlinks=true,
|
||||
linkcolor=blue
|
||||
]{hyperref}
|
||||
\usepackage{pspicture}
|
||||
\else
|
||||
\usepackage[pdftex,
|
||||
pagebackref=true,
|
||||
colorlinks=true,
|
||||
linkcolor=blue
|
||||
]{hyperref}
|
||||
\fi
|
||||
\usepackage{doxygen}
|
||||
\makeindex
|
||||
\setcounter{tocdepth}{1}
|
||||
\renewcommand{\footrulewidth}{0.4pt}
|
||||
\begin{document}
|
||||
\begin{titlepage}
|
||||
\vspace*{5cm}
|
||||
\begin{center}
|
||||
{\Huge Protothreads}\\
|
||||
\vspace*{1cm}
|
||||
{\LARGE The Protothreads Library 1.3 Reference Manual}\\
|
||||
\vspace*{3cm}
|
||||
{\Large June 2006}\\
|
||||
\vspace*{2cm}
|
||||
\includegraphics[width=6cm]{../sicslogo.pdf}\\
|
||||
\vspace*{1cm}
|
||||
{\Large Adam Dunkels}\\
|
||||
{\Large \texttt{adam@sics.se}}\\
|
||||
\vspace*{1cm}
|
||||
{\LARGE Swedish Institute of Computer Science}\\
|
||||
\vspace*{0.5cm}
|
||||
|
||||
\end{center}
|
||||
\end{titlepage}
|
||||
\pagenumbering{roman}
|
||||
\tableofcontents
|
||||
\pagenumbering{arabic}
|
|
@ -0,0 +1,40 @@
|
|||
<!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.4: pt Struct Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt Struct Reference<br>
|
||||
<small>
|
||||
[<a class="el" href="a00014.html">Protothreads</a>]</small>
|
||||
</h1><!-- doxytag: class="pt" --><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
|
||||
<p>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00054">54</a> of file <a class="el" href="a00022.html">pt.h</a>.<table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Data Fields</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="c3fa0fa86689e3e7c039a16c16861dbe"></a><!-- doxytag: member="pt::lc" ref="c3fa0fa86689e3e7c039a16c16861dbe" args="" -->
|
||||
<a class="el" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">lc_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="a00005.html#c3fa0fa86689e3e7c039a16c16861dbe">lc</a></td></tr>
|
||||
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,40 @@
|
|||
<!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.4: pt_sem Struct Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt_sem Struct Reference<br>
|
||||
<small>
|
||||
[<a class="el" href="a00016.html">Protothread semaphores</a>]</small>
|
||||
</h1><!-- doxytag: class="pt_sem" --><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
|
||||
<p>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00021.html#l00165">165</a> of file <a class="el" href="a00021.html">pt-sem.h</a>.<table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Data Fields</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="6f341120f42d5fd9f329ff1119594743"></a><!-- doxytag: member="pt_sem::count" ref="6f341120f42d5fd9f329ff1119594743" args="" -->
|
||||
unsigned int </td><td class="memItemRight" valign="bottom"><a class="el" href="a00006.html#6f341120f42d5fd9f329ff1119594743">count</a></td></tr>
|
||||
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,61 @@
|
|||
<!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.4: lc-addrlabels.h File Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc-addrlabels.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Implementation of local continuations based on the "Labels as values" feature of gcc.
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>></dd></dl>
|
||||
This implementation of local continuations is based on a special feature of the GCC C compiler called "labels as values". This feature allows assigning pointers with the address of the code corresponding to a particular C label.<p>
|
||||
For more information, see the GCC documentation: <a href="http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html">http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html</a>
|
||||
<p>
|
||||
Definition in file <a class="el" href="a00018.html">lc-addrlabels.h</a>.
|
||||
<p>
|
||||
|
||||
<p>
|
||||
<a href="a00018.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></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="g2c1bb4fa6d7a6ff951a41c73fc721109"></a><!-- doxytag: member="lc-addrlabels.h::LC_INIT" ref="g2c1bb4fa6d7a6ff951a41c73fc721109" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">LC_INIT</a>(s) s = NULL</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g1ec8b8f4710dce1fa7fb87d3a31541ae"></a><!-- doxytag: member="lc-addrlabels.h::LC_RESUME" ref="g1ec8b8f4710dce1fa7fb87d3a31541ae" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">LC_RESUME</a>(s)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g6e1e879e172e2d8838e5f567dac8918c"></a><!-- doxytag: member="lc-addrlabels.h::LC_CONCAT2" ref="g6e1e879e172e2d8838e5f567dac8918c" args="(s1, s2)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g6e1e879e172e2d8838e5f567dac8918c">LC_CONCAT2</a>(s1, s2) s1##s2</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2b1f9b9fe8b6895b156f0af10538971c"></a><!-- doxytag: member="lc-addrlabels.h::LC_CONCAT" ref="g2b1f9b9fe8b6895b156f0af10538971c" args="(s1, s2)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2b1f9b9fe8b6895b156f0af10538971c">LC_CONCAT</a>(s1, s2) LC_CONCAT2(s1, s2)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gd8eec328a4868d767f0c00c8d1c6cfc1"></a><!-- doxytag: member="lc-addrlabels.h::LC_SET" ref="gd8eec328a4868d767f0c00c8d1c6cfc1" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">LC_SET</a>(s)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gca51ceb2f5d855dfde55bcedf8d3b92d"></a><!-- doxytag: member="lc-addrlabels.h::LC_END" ref="gca51ceb2f5d855dfde55bcedf8d3b92d" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">LC_END</a>(s)</td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Typedefs</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2bdc4b7b4038454a79f1b2a94a6d2a98"></a><!-- doxytag: member="lc-addrlabels.h::lc_t" ref="g2bdc4b7b4038454a79f1b2a94a6d2a98" args="" -->
|
||||
typedef void * </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">lc_t</a></td></tr>
|
||||
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,56 @@
|
|||
<!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.4: lc-switch.h File Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc-switch.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Implementation of local continuations based on switch() statment.
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>></dd></dl>
|
||||
This implementation of local continuations uses the C switch() statement to resume execution of a function somewhere inside the function's body. The implementation is based on the fact that switch() statements are able to jump directly into the bodies of control structures such as if() or while() statmenets.<p>
|
||||
This implementation borrows heavily from Simon Tatham's coroutines implementation in C: <a href="http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html">http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html</a>
|
||||
<p>
|
||||
Definition in file <a class="el" href="a00019.html">lc-switch.h</a>.
|
||||
<p>
|
||||
|
||||
<p>
|
||||
<a href="a00019.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></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="g2c1bb4fa6d7a6ff951a41c73fc721109"></a><!-- doxytag: member="lc-switch.h::LC_INIT" ref="g2c1bb4fa6d7a6ff951a41c73fc721109" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">LC_INIT</a>(s) s = 0;</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g1ec8b8f4710dce1fa7fb87d3a31541ae"></a><!-- doxytag: member="lc-switch.h::LC_RESUME" ref="g1ec8b8f4710dce1fa7fb87d3a31541ae" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">LC_RESUME</a>(s) switch(s) { case 0:</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gd8eec328a4868d767f0c00c8d1c6cfc1"></a><!-- doxytag: member="lc-switch.h::LC_SET" ref="gd8eec328a4868d767f0c00c8d1c6cfc1" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">LC_SET</a>(s) s = __LINE__; case __LINE__:</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gca51ceb2f5d855dfde55bcedf8d3b92d"></a><!-- doxytag: member="lc-switch.h::LC_END" ref="gca51ceb2f5d855dfde55bcedf8d3b92d" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">LC_END</a>(s) }</td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Typedefs</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gfad6704adb116cc16edb80f744e7239d"></a><!-- doxytag: member="lc-switch.h::lc_t" ref="gfad6704adb116cc16edb80f744e7239d" args="" -->
|
||||
typedef unsigned short </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc_t</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">The local continuation type. <br></td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,51 @@
|
|||
<!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.4: lc.h File Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Local continuations.
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>> </dd></dl>
|
||||
|
||||
<p>
|
||||
Definition in file <a class="el" href="a00020.html">lc.h</a>.
|
||||
<p>
|
||||
<code>#include "<a class="el" href="a00019.html">lc-switch.h</a>"</code><br>
|
||||
|
||||
<p>
|
||||
<a href="a00020.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76">LC_INIT</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a local continuation. <a href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341">LC_SET</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set a local continuation. <a href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3">LC_RESUME</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Resume a local continuation. <a href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g3d76802e55349cc8bf74f286ced203c3">LC_END</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Mark the end of local continuation usage. <a href="a00017.html#g3d76802e55349cc8bf74f286ced203c3"></a><br></td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,51 @@
|
|||
<!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.4: pt-sem.h File Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt-sem.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Couting semaphores implemented on protothreads.
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>> </dd></dl>
|
||||
|
||||
<p>
|
||||
Definition in file <a class="el" href="a00021.html">pt-sem.h</a>.
|
||||
<p>
|
||||
<code>#include "<a class="el" href="a00022.html">pt.h</a>"</code><br>
|
||||
|
||||
<p>
|
||||
<a href="a00021.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct </td><td class="memItemRight" valign="bottom"><a class="el" href="a00006.html">pt_sem</a></td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(s, c)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a semaphore. <a href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(<a class="el" href="a00005.html">pt</a>, s)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Wait for a semaphore. <a href="a00016.html#g386ff87a52a840512906f2940e229e2e"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(<a class="el" href="a00005.html">pt</a>, s)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Signal a semaphore. <a href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19"></a><br></td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,100 @@
|
|||
<!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.4: pt.h File Reference</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt.h File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Protothreads implementation.
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>> </dd></dl>
|
||||
|
||||
<p>
|
||||
Definition in file <a class="el" href="a00022.html">pt.h</a>.
|
||||
<p>
|
||||
<code>#include "<a class="el" href="a00020.html">lc.h</a>"</code><br>
|
||||
|
||||
<p>
|
||||
<a href="a00022.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
<tr><td colspan="2"><br><h2>Data Structures</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct </td><td class="memItemRight" valign="bottom"><a class="el" href="a00005.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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a protothread. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(name_args)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Declaration of a protothread. <a href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Declare the start of a protothread inside the C function implementing the protothread. <a href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Declare the end of a protothread. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(<a class="el" href="a00005.html">pt</a>, condition)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Block and wait until condition is true. <a href="a00014.html#g99e43010ec61327164466aa2d902de45"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d">PT_WAIT_WHILE</a>(<a class="el" href="a00005.html">pt</a>, cond)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Block and wait while condition is true. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD</a>(<a class="el" href="a00005.html">pt</a>, thread)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Block and wait until a child protothread completes. <a href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN</a>(<a class="el" href="a00005.html">pt</a>, child, thread)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Spawn a child protothread and wait until it exits. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">PT_RESTART</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Restart the protothread. <a href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">PT_EXIT</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Exit the protothread. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(f)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Schedule a protothread. <a href="a00014.html#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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g155cba6121323726d02c00284428fed6">PT_YIELD</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Yield from the current protothread. <a href="a00014.html#g155cba6121323726d02c00284428fed6"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge3c821e3a388615528efda9d23c7d115">PT_YIELD_UNTIL</a>(<a class="el" href="a00005.html">pt</a>, cond)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Yield from the protothread until a condition occurs. <a href="a00014.html#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.h::PT_WAITING" ref="g7b5319b5b65761a845fcd1500fde4cdc" args="" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g7b5319b5b65761a845fcd1500fde4cdc">PT_WAITING</a> 0</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ge469332907e0617d72d5e2dd4297119d"></a><!-- doxytag: member="pt.h::PT_YIELDED" ref="ge469332907e0617d72d5e2dd4297119d" args="" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge469332907e0617d72d5e2dd4297119d">PT_YIELDED</a> 1</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gcfae9053e5c107a1aed6b228c917d2ea"></a><!-- doxytag: member="pt.h::PT_EXITED" ref="gcfae9053e5c107a1aed6b228c917d2ea" args="" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gcfae9053e5c107a1aed6b228c917d2ea">PT_EXITED</a> 2</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g9ff1e8936a8a26bff54c05f8a989b93b"></a><!-- doxytag: member="pt.h::PT_ENDED" ref="g9ff1e8936a8a26bff54c05f8a989b93b" args="" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g9ff1e8936a8a26bff54c05f8a989b93b">PT_ENDED</a> 3</td></tr>
|
||||
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,627 @@
|
|||
<!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.4: 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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></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="a00013.html">pt.h</a>, which includes the local continuations header file, <a class="el" href="a00011.html">lc.h</a>.
|
||||
<p>
|
||||
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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00013.html">pt.h</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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"> </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html">Protothread semaphores</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">This module implements counting semaphores on top of protothreads. <br></td></tr>
|
||||
|
||||
<p>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html">Local continuations</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00005.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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(name_args)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(<a class="el" href="a00005.html">pt</a>, condition)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d">PT_WAIT_WHILE</a>(<a class="el" href="a00005.html">pt</a>, cond)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD</a>(<a class="el" href="a00005.html">pt</a>, thread)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN</a>(<a class="el" href="a00005.html">pt</a>, child, thread)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">PT_RESTART</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Restart the protothread. <a href="#gcd3ac045f0a4ae63412e3b3d8780e8ab"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">PT_EXIT</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(f)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g155cba6121323726d02c00284428fed6">PT_YIELD</a>(<a class="el" href="a00005.html">pt</a>)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge3c821e3a388615528efda9d23c7d115">PT_YIELD_UNTIL</a>(<a class="el" href="a00005.html">pt</a>, cond)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g7b5319b5b65761a845fcd1500fde4cdc">PT_WAITING</a> 0</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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#ge469332907e0617d72d5e2dd4297119d">PT_YIELDED</a> 1</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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#gcfae9053e5c107a1aed6b228c917d2ea">PT_EXITED</a> 2</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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00014.html#g9ff1e8936a8a26bff54c05f8a989b93b">PT_ENDED</a> 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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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="a00014.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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00115">115</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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="a00014.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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00127">127</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00246">246</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </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="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN()</a> </dd></dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00080">80</a> of file <a class="el" href="a00022.html">pt.h</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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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="a00014.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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00229">229</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top">f </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </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="a00022.html#l00271">271</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.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 </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>child</em> </td><td>A pointer to the child protothread's control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>thread</em> </td><td>The child protothread with arguments </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00206">206</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top">name_args </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>The name and arguments of the C function implementing the protothread. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00100">100</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>thread </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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="a00014.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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>thread</em> </td><td>The child protothread with arguments</td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">PT_SPAWN()</a> </dd></dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00192">192</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>condition </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>condition</em> </td><td>The condition. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00148">148</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>cond </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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="a00014.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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>cond</em> </td><td>The condition. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00167">167</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a> </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00022.html#l00290">290</a> of file <a class="el" href="a00022.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">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>cond </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</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> </td><td>A pointer to the protothread control structure. </td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>cond</em> </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="a00022.html#l00310">310</a> of file <a class="el" href="a00022.html">pt.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,711 @@
|
|||
<!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.4: Examples</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<h1>Examples</h1><h2><a class="anchor" name="example-small">
|
||||
A small example</a></h2>
|
||||
This first example shows a very simple program: two protothreads waiting for each other to toggle two flags. The code illustrates how to write protothreads code, how to initialize protothreads, and how to schedule them.<p>
|
||||
<div class="fragment"><pre class="fragment"><span class="comment">/**</span>
|
||||
<span class="comment"> * This is a very small example that shows how to use</span>
|
||||
<span class="comment"> * protothreads. The program consists of two protothreads that wait</span>
|
||||
<span class="comment"> * for each other to toggle a variable.</span>
|
||||
<span class="comment"> */</span>
|
||||
|
||||
<span class="comment">/* We must always include pt.h in our protothreads code. */</span>
|
||||
<span class="preprocessor">#include "<a class="code" href="a00013.html">pt.h</a>"</span>
|
||||
|
||||
<span class="preprocessor">#include <stdio.h></span> <span class="comment">/* For printf(). */</span>
|
||||
|
||||
<span class="comment">/* Two flags that the two protothread functions use. */</span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> protothread1_flag, protothread2_flag;
|
||||
<span class="comment"></span>
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * The first protothread function. A protothread function must always</span>
|
||||
<span class="comment"> * return an integer, but must never explicitly return - returning is</span>
|
||||
<span class="comment"> * performed inside the protothread statements.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * The protothread function is driven by the main loop further down in</span>
|
||||
<span class="comment"> * the code.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span>
|
||||
protothread1(<span class="keyword">struct</span> <a class="code" href="a00005.html">pt</a> *<a class="code" href="a00005.html">pt</a>)
|
||||
{
|
||||
<span class="comment">/* A protothread function must begin with PT_BEGIN() which takes a</span>
|
||||
<span class="comment"> pointer to a struct pt. */</span>
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="comment">/* We loop forever here. */</span>
|
||||
<span class="keywordflow">while</span>(1) {
|
||||
<span class="comment">/* Wait until the other protothread has set its flag. */</span>
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, protothread2_flag != 0);
|
||||
printf(<span class="stringliteral">"Protothread 1 running\n"</span>);
|
||||
|
||||
<span class="comment">/* We then reset the other protothread's flag, and set our own</span>
|
||||
<span class="comment"> flag so that the other protothread can run. */</span>
|
||||
protothread2_flag = 0;
|
||||
protothread1_flag = 1;
|
||||
|
||||
<span class="comment">/* And we loop. */</span>
|
||||
}
|
||||
|
||||
<span class="comment">/* All protothread functions must end with PT_END() which takes a</span>
|
||||
<span class="comment"> pointer to a struct pt. */</span>
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
<span class="comment"></span>
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * The second protothread function. This is almost the same as the</span>
|
||||
<span class="comment"> * first one.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span>
|
||||
protothread2(<span class="keyword">struct</span> pt *pt)
|
||||
{
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="keywordflow">while</span>(1) {
|
||||
<span class="comment">/* Let the other protothread run. */</span>
|
||||
protothread2_flag = 1;
|
||||
|
||||
<span class="comment">/* Wait until the other protothread has set its flag. */</span>
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, protothread1_flag != 0);
|
||||
printf(<span class="stringliteral">"Protothread 2 running\n"</span>);
|
||||
|
||||
<span class="comment">/* We then reset the other protothread's flag. */</span>
|
||||
protothread1_flag = 0;
|
||||
|
||||
<span class="comment">/* And we loop. */</span>
|
||||
}
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
<span class="comment"></span>
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * Finally, we have the main loop. Here is where the protothreads are</span>
|
||||
<span class="comment"> * initialized and scheduled. First, however, we define the</span>
|
||||
<span class="comment"> * protothread state variables pt1 and pt2, which hold the state of</span>
|
||||
<span class="comment"> * the two protothreads.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span>pt pt1, pt2;
|
||||
<span class="keywordtype">int</span>
|
||||
main(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="comment">/* Initialize the protothread state variables with PT_INIT(). */</span>
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt1);
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt2);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Then we schedule the two protothreads by repeatedly calling their</span>
|
||||
<span class="comment"> * protothread functions and passing a pointer to the protothread</span>
|
||||
<span class="comment"> * state variables as arguments.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">while</span>(1) {
|
||||
protothread1(&pt1);
|
||||
protothread2(&pt2);
|
||||
}
|
||||
}
|
||||
</pre></div><h2><a class="anchor" name="example-code-lock">
|
||||
A code-lock</a></h2>
|
||||
This example shows how to implement a simple code lock - the kind of device that is placed next to doors and that you have to push a four digit number into in order to unlock the door.<p>
|
||||
The code lock waits for key presses from a numeric keyboard and if the correct code is entered, the lock is unlocked. There is a maximum time of one second between each key press, and after the correct code has been entered, no more keys must be pressed for 0.5 seconds before the lock is opened.<p>
|
||||
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
|
||||
<span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<span class="comment"> * All rights reserved. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * Redistribution and use in source and binary forms, with or without </span>
|
||||
<span class="comment"> * modification, are permitted provided that the following conditions </span>
|
||||
<span class="comment"> * are met: </span>
|
||||
<span class="comment"> * 1. Redistributions of source code must retain the above copyright </span>
|
||||
<span class="comment"> * notice, this list of conditions and the following disclaimer. </span>
|
||||
<span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright </span>
|
||||
<span class="comment"> * notice, this list of conditions and the following disclaimer in the </span>
|
||||
<span class="comment"> * documentation and/or other materials provided with the distribution. </span>
|
||||
<span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors </span>
|
||||
<span class="comment"> * may be used to endorse or promote products derived from this software </span>
|
||||
<span class="comment"> * without specific prior written permission. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND </span>
|
||||
<span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </span>
|
||||
<span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE </span>
|
||||
<span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE </span>
|
||||
<span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </span>
|
||||
<span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS </span>
|
||||
<span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) </span>
|
||||
<span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT </span>
|
||||
<span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY </span>
|
||||
<span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF </span>
|
||||
<span class="comment"> * SUCH DAMAGE. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * This file is part of the protothreads library.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * $Id: example-codelock.c,v 1.5 2005/10/06 07:57:08 adam Exp $</span>
|
||||
<span class="comment"> */</span>
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * This example shows how to implement a simple code lock. The code</span>
|
||||
<span class="comment"> * lock waits for key presses from a numeric keyboard and if the</span>
|
||||
<span class="comment"> * correct code is entered, the lock is unlocked. There is a maximum</span>
|
||||
<span class="comment"> * time of one second between each key press, and after the correct</span>
|
||||
<span class="comment"> * code has been entered, no more keys must be pressed for 0.5 seconds</span>
|
||||
<span class="comment"> * before the lock is opened.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * This is an example that shows two things:</span>
|
||||
<span class="comment"> * - how to implement a code lock key input mechanism, and</span>
|
||||
<span class="comment"> * - how to implement a sequential timed routine.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * The program consists of two protothreads, one that implements the</span>
|
||||
<span class="comment"> * code lock reader and one that implements simulated keyboard input.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> */</span>
|
||||
|
||||
<span class="preprocessor">#ifdef _WIN32</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>
|
||||
<span class="preprocessor">#else</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <unistd.h></span>
|
||||
<span class="preprocessor">#include <sys/time.h></span>
|
||||
<span class="preprocessor">#endif</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
|
||||
|
||||
<span class="preprocessor">#include "<a class="code" href="a00013.html">pt.h</a>"</span>
|
||||
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * The following definitions are just for the simple timer library</span>
|
||||
<span class="comment"> * used in this example. The actual implementation of the functions</span>
|
||||
<span class="comment"> * can be found at the end of this file.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">struct </span>timer { <span class="keywordtype">int</span> start, interval; };
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> timer_expired(<span class="keyword">struct</span> timer *t);
|
||||
<span class="keyword">static</span> <span class="keywordtype">void</span> timer_set(<span class="keyword">struct</span> timer *t, <span class="keywordtype">int</span> usecs);
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * This example uses two timers: one for the code lock protothread and</span>
|
||||
<span class="comment"> * one for the simulated key input protothread.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span>timer codelock_timer, input_timer;
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * This is the code that has to be entered.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> code[4] = {<span class="charliteral">'1'</span>, <span class="charliteral">'4'</span>, <span class="charliteral">'2'</span>, <span class="charliteral">'3'</span>};
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * This example has two protothread and therefor has two protothread</span>
|
||||
<span class="comment"> * control structures of type struct pt. These are initialized with</span>
|
||||
<span class="comment"> * PT_INIT() in the main() function below.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span>pt codelock_pt, input_pt;
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * The following code implements a simple key input. Input is made</span>
|
||||
<span class="comment"> * with the press_key() function, and the function key_pressed()</span>
|
||||
<span class="comment"> * checks if a key has been pressed. The variable "key" holds the</span>
|
||||
<span class="comment"> * latest key that was pressed. The variable "key_pressed_flag" is set</span>
|
||||
<span class="comment"> * when a key is pressed and cleared when a key press is checked.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">char</span> key, key_pressed_flag;
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">void</span>
|
||||
press_key(<span class="keywordtype">char</span> k)
|
||||
{
|
||||
printf(<span class="stringliteral">"--- Key '%c' pressed\n"</span>, k);
|
||||
key = k;
|
||||
key_pressed_flag = 1;
|
||||
}
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span>
|
||||
key_pressed(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="keywordflow">if</span>(key_pressed_flag != 0) {
|
||||
key_pressed_flag = 0;
|
||||
<span class="keywordflow">return</span> 1;
|
||||
}
|
||||
<span class="keywordflow">return</span> 0;
|
||||
}
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Declaration of the protothread function implementing the code lock</span>
|
||||
<span class="comment"> * logic. The protothread function is declared using the PT_THREAD()</span>
|
||||
<span class="comment"> * macro. The function is declared with the "static" keyword since it</span>
|
||||
<span class="comment"> * is local to this file. The name of the function is codelock_thread</span>
|
||||
<span class="comment"> * and it takes one argument, pt, of the type struct pt.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span>
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(codelock_thread(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="comment">/* This is a local variable that holds the number of keys that have</span>
|
||||
<span class="comment"> * been pressed. Note that it is declared with the "static" keyword</span>
|
||||
<span class="comment"> * to make sure that the variable is *not* allocated on the stack.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> keys;
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Declare the beginning of the protothread.</span>
|
||||
<span class="comment"> */</span>
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * We'll let the protothread loop until the protothread is</span>
|
||||
<span class="comment"> * expliticly exited with PT_EXIT().</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">while</span>(1) {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * We'll be reading key presses until we get the right amount of</span>
|
||||
<span class="comment"> * correct keys.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">for</span>(keys = 0; keys < <span class="keyword">sizeof</span>(code); ++keys) {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * If we haven't gotten any keypresses, we'll simply wait for one.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">if</span>(keys == 0) {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * The PT_WAIT_UNTIL() function will block until the condition</span>
|
||||
<span class="comment"> * key_pressed() is true.</span>
|
||||
<span class="comment"> */</span>
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, key_pressed());
|
||||
} <span class="keywordflow">else</span> {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * If the "key" variable was larger than zero, we have already</span>
|
||||
<span class="comment"> * gotten at least one correct key press. If so, we'll not</span>
|
||||
<span class="comment"> * only wait for the next key, but we'll also set a timer that</span>
|
||||
<span class="comment"> * expires in one second. This gives the person pressing the</span>
|
||||
<span class="comment"> * keys one second to press the next key in the code.</span>
|
||||
<span class="comment"> */</span>
|
||||
timer_set(&codelock_timer, 1000);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * The following statement shows how complex blocking</span>
|
||||
<span class="comment"> * conditions can be easily expressed with protothreads and</span>
|
||||
<span class="comment"> * the PT_WAIT_UNTIL() function.</span>
|
||||
<span class="comment"> */</span>
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, key_pressed() || timer_expired(&codelock_timer));
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * If the timer expired, we should break out of the for() loop</span>
|
||||
<span class="comment"> * and start reading keys from the beginning of the while(1)</span>
|
||||
<span class="comment"> * loop instead.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">if</span>(timer_expired(&codelock_timer)) {
|
||||
printf(<span class="stringliteral">"Code lock timer expired.\n"</span>);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Break out from the for() loop and start from the</span>
|
||||
<span class="comment"> * beginning of the while(1) loop.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">break</span>;
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Check if the pressed key was correct.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">if</span>(key != code[keys]) {
|
||||
printf(<span class="stringliteral">"Incorrect key '%c' found\n"</span>, key);
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Break out of the for() loop since the key was incorrect.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">break</span>;
|
||||
} <span class="keywordflow">else</span> {
|
||||
printf(<span class="stringliteral">"Correct key '%c' found\n"</span>, key);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Check if we have gotten all keys.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">if</span>(keys == <span class="keyword">sizeof</span>(code)) {
|
||||
printf(<span class="stringliteral">"Correct code entered, waiting for 500 ms before unlocking.\n"</span>);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Ok, we got the correct code. But to make sure that the code</span>
|
||||
<span class="comment"> * was not just a fluke of luck by an intruder, but the correct</span>
|
||||
<span class="comment"> * code entered by a person that knows the correct code, we'll</span>
|
||||
<span class="comment"> * wait for half a second before opening the lock. If another</span>
|
||||
<span class="comment"> * key is pressed during this time, we'll assume that it was a</span>
|
||||
<span class="comment"> * fluke of luck that the correct code was entered the first</span>
|
||||
<span class="comment"> * time.</span>
|
||||
<span class="comment"> */</span>
|
||||
timer_set(&codelock_timer, 500);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, key_pressed() || timer_expired(&codelock_timer));
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * If we continued from the PT_WAIT_UNTIL() statement without</span>
|
||||
<span class="comment"> * the timer expired, we don't open the lock.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">if</span>(!timer_expired(&codelock_timer)) {
|
||||
printf(<span class="stringliteral">"Key pressed during final wait, code lock locked again.\n"</span>);
|
||||
} <span class="keywordflow">else</span> {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * If the timer expired, we'll open the lock and exit from the</span>
|
||||
<span class="comment"> * protothread.</span>
|
||||
<span class="comment"> */</span>
|
||||
printf(<span class="stringliteral">"Code lock unlocked.\n"</span>);
|
||||
<a class="code" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">PT_EXIT</a>(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Finally, we'll mark the end of the protothread.</span>
|
||||
<span class="comment"> */</span>
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * This is the second protothread in this example. It implements a</span>
|
||||
<span class="comment"> * simulated user pressing the keys. This illustrates how a linear</span>
|
||||
<span class="comment"> * sequence of timed instructions can be implemented with</span>
|
||||
<span class="comment"> * protothreads.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keyword">static</span>
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(input_thread(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
printf(<span class="stringliteral">"Waiting 1 second before entering first key.\n"</span>);
|
||||
|
||||
timer_set(&input_timer, 1000);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'1'</span>);
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'2'</span>);
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'3'</span>);
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'1'</span>);
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'4'</span>);
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'2'</span>);
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'3'</span>);
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'1'</span>);
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'4'</span>);
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'2'</span>);
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'3'</span>);
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'4'</span>);
|
||||
|
||||
timer_set(&input_timer, 1500);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'1'</span>);
|
||||
|
||||
timer_set(&input_timer, 300);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'4'</span>);
|
||||
|
||||
timer_set(&input_timer, 400);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'2'</span>);
|
||||
|
||||
timer_set(&input_timer, 500);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key(<span class="charliteral">'3'</span>);
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
<a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL</a>(pt, timer_expired(&input_timer));
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * This is the main function. It initializes the two protothread</span>
|
||||
<span class="comment"> * control structures and schedules the two protothreads. The main</span>
|
||||
<span class="comment"> * function returns when the protothread the runs the code lock exits.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordtype">int</span>
|
||||
main(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Initialize the two protothread control structures.</span>
|
||||
<span class="comment"> */</span>
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&input_pt);
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&codelock_pt);
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Schedule the two protothreads until the codelock_thread() exits.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="keywordflow">while</span>(<a class="code" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(codelock_thread(&codelock_pt))) {
|
||||
<a class="code" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(input_thread(&input_pt));
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * When running this example on a multitasking system, we must</span>
|
||||
<span class="comment"> * give other processes a chance to run too and therefore we call</span>
|
||||
<span class="comment"> * usleep() resp. Sleep() here. On a dedicated embedded system,</span>
|
||||
<span class="comment"> * we usually do not need to do this.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="preprocessor">#ifdef _WIN32</span>
|
||||
<span class="preprocessor"></span> Sleep(0);
|
||||
<span class="preprocessor">#else</span>
|
||||
<span class="preprocessor"></span> usleep(10);
|
||||
<span class="preprocessor">#endif</span>
|
||||
<span class="preprocessor"></span> }
|
||||
|
||||
<span class="keywordflow">return</span> 0;
|
||||
}
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Finally, the implementation of the simple timer library follows.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="preprocessor">#ifdef _WIN32</span>
|
||||
<span class="preprocessor"></span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> clock_time(<span class="keywordtype">void</span>)
|
||||
{ <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)GetTickCount(); }
|
||||
|
||||
<span class="preprocessor">#else </span><span class="comment">/* _WIN32 */</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> clock_time(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="keyword">struct </span>timeval tv;
|
||||
<span class="keyword">struct </span>timezone tz;
|
||||
gettimeofday(&tv, &tz);
|
||||
<span class="keywordflow">return</span> tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
<span class="preprocessor">#endif </span><span class="comment">/* _WIN32 */</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> timer_expired(<span class="keyword">struct</span> timer *t)
|
||||
{ <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)(clock_time() - t->start) >= (<span class="keywordtype">int</span>)t->interval; }
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">void</span> timer_set(<span class="keyword">struct</span> timer *t, <span class="keywordtype">int</span> interval)
|
||||
{ t->interval = interval; t->start = clock_time(); }
|
||||
<span class="comment">/*---------------------------------------------------------------------------*/</span>
|
||||
</pre></div><h2><a class="anchor" name="example-buffer">
|
||||
The bounded buffer with protothread semaphores</a></h2>
|
||||
The following example shows how to implement the bounded buffer problem using the protothreads semaphore library. The example uses three protothreads: one producer() protothread that produces items, one consumer() protothread that consumes items, and one driver_thread() that schedules the producer and consumer protothreads.<p>
|
||||
Note that there is no need for a mutex to guard the add_to_buffer() and get_from_buffer() functions because of the implicit locking semantics of protothreads - a protothread will never be preempted and will never block except in an explicit PT_WAIT statement.<p>
|
||||
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
|
||||
<span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<span class="comment"> * All rights reserved. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * Redistribution and use in source and binary forms, with or without </span>
|
||||
<span class="comment"> * modification, are permitted provided that the following conditions </span>
|
||||
<span class="comment"> * are met: </span>
|
||||
<span class="comment"> * 1. Redistributions of source code must retain the above copyright </span>
|
||||
<span class="comment"> * notice, this list of conditions and the following disclaimer. </span>
|
||||
<span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright </span>
|
||||
<span class="comment"> * notice, this list of conditions and the following disclaimer in the </span>
|
||||
<span class="comment"> * documentation and/or other materials provided with the distribution. </span>
|
||||
<span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors </span>
|
||||
<span class="comment"> * may be used to endorse or promote products derived from this software </span>
|
||||
<span class="comment"> * without specific prior written permission. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND </span>
|
||||
<span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </span>
|
||||
<span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE </span>
|
||||
<span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE </span>
|
||||
<span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </span>
|
||||
<span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS </span>
|
||||
<span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) </span>
|
||||
<span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT </span>
|
||||
<span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY </span>
|
||||
<span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF </span>
|
||||
<span class="comment"> * SUCH DAMAGE. </span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * This file is part of the protothreads library.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * $Id: example-buffer.c,v 1.5 2005/10/07 05:21:33 adam Exp $</span>
|
||||
<span class="comment"> */</span>
|
||||
|
||||
<span class="preprocessor">#ifdef _WIN32</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>
|
||||
<span class="preprocessor">#else</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <unistd.h></span>
|
||||
<span class="preprocessor">#endif</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#include <stdio.h></span>
|
||||
|
||||
<span class="preprocessor">#include "<a class="code" href="a00012.html">pt-sem.h</a>"</span>
|
||||
|
||||
<span class="preprocessor">#define NUM_ITEMS 32</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#define BUFSIZE 8</span>
|
||||
<span class="preprocessor"></span>
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> buffer[BUFSIZE];
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> bufptr;
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">void</span>
|
||||
add_to_buffer(<span class="keywordtype">int</span> item)
|
||||
{
|
||||
printf(<span class="stringliteral">"Item %d added to buffer at place %d\n"</span>, item, bufptr);
|
||||
buffer[bufptr] = item;
|
||||
bufptr = (bufptr + 1) % BUFSIZE;
|
||||
}
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span>
|
||||
get_from_buffer(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="keywordtype">int</span> item;
|
||||
item = buffer[bufptr];
|
||||
printf(<span class="stringliteral">"Item %d retrieved from buffer at place %d\n"</span>,
|
||||
item, bufptr);
|
||||
bufptr = (bufptr + 1) % BUFSIZE;
|
||||
<span class="keywordflow">return</span> item;
|
||||
}
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span>
|
||||
produce_item(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> item = 0;
|
||||
printf(<span class="stringliteral">"Item %d produced\n"</span>, item);
|
||||
<span class="keywordflow">return</span> item++;
|
||||
}
|
||||
|
||||
<span class="keyword">static</span> <span class="keywordtype">void</span>
|
||||
consume_item(<span class="keywordtype">int</span> item)
|
||||
{
|
||||
printf(<span class="stringliteral">"Item %d consumed\n"</span>, item);
|
||||
}
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="a00006.html">pt_sem</a> full, empty;
|
||||
|
||||
<span class="keyword">static</span>
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(producer(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> produced;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="keywordflow">for</span>(produced = 0; produced < NUM_ITEMS; ++produced) {
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &full);
|
||||
|
||||
add_to_buffer(produce_item());
|
||||
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &empty);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
|
||||
<span class="keyword">static</span>
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(consumer(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> consumed;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="keywordflow">for</span>(consumed = 0; consumed < NUM_ITEMS; ++consumed) {
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &empty);
|
||||
|
||||
consume_item(get_from_buffer());
|
||||
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &full);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
|
||||
<span class="keyword">static</span>
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(driver_thread(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span>pt pt_producer, pt_consumer;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(&empty, 0);
|
||||
<a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(&full, BUFSIZE);
|
||||
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt_producer);
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt_consumer);
|
||||
|
||||
<a class="code" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD</a>(pt, producer(&pt_producer) &
|
||||
consumer(&pt_consumer));
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
|
||||
|
||||
<span class="keywordtype">int</span>
|
||||
main(<span class="keywordtype">void</span>)
|
||||
{
|
||||
<span class="keyword">struct </span>pt driver_pt;
|
||||
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&driver_pt);
|
||||
|
||||
<span class="keywordflow">while</span>(<a class="code" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">PT_SCHEDULE</a>(driver_thread(&driver_pt))) {
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * When running this example on a multitasking system, we must</span>
|
||||
<span class="comment"> * give other processes a chance to run too and therefore we call</span>
|
||||
<span class="comment"> * usleep() resp. Sleep() here. On a dedicated embedded system,</span>
|
||||
<span class="comment"> * we usually do not need to do this.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="preprocessor">#ifdef _WIN32</span>
|
||||
<span class="preprocessor"></span> Sleep(0);
|
||||
<span class="preprocessor">#else</span>
|
||||
<span class="preprocessor"></span> usleep(10);
|
||||
<span class="preprocessor">#endif</span>
|
||||
<span class="preprocessor"></span> }
|
||||
<span class="keywordflow">return</span> 0;
|
||||
}
|
||||
</pre></div>
|
||||
<p>
|
||||
<table border="0" cellpadding="0" cellspacing="0">
|
||||
<tr><td></td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,246 @@
|
|||
<!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.4: Protothread semaphores</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<h1>Protothread semaphores<br>
|
||||
<small>
|
||||
[<a class="el" href="a00014.html">Protothreads</a>]</small>
|
||||
</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
This module implements counting semaphores on top of protothreads.
|
||||
<p>
|
||||
Semaphores are a synchronization primitive that provide two operations: "wait" and "signal". The "wait" operation checks the semaphore counter and blocks the thread if the counter is zero. The "signal" operation increases the semaphore counter but does not block. If another thread has blocked waiting for the semaphore that is signalled, the blocked thread will become runnable again.<p>
|
||||
Semaphores can be used to implement other, more structured, synchronization primitives such as monitors and message queues/bounded buffers (see below).<p>
|
||||
The following example shows how the producer-consumer problem, also known as the bounded buffer problem, can be solved using protothreads and semaphores. Notes on the program follow after the example.<p>
|
||||
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="a00012.html">pt-sem.h</a>"</span>
|
||||
|
||||
<span class="preprocessor">#define NUM_ITEMS 32</span>
|
||||
<span class="preprocessor"></span><span class="preprocessor">#define BUFSIZE 8</span>
|
||||
<span class="preprocessor"></span>
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="a00006.html">pt_sem</a> mutex, full, empty;
|
||||
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(producer(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> produced;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="keywordflow">for</span>(produced = 0; produced < NUM_ITEMS; ++produced) {
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &full);
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &mutex);
|
||||
add_to_buffer(produce_item());
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &mutex);
|
||||
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &empty);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(consumer(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keywordtype">int</span> consumed;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<span class="keywordflow">for</span>(consumed = 0; consumed < NUM_ITEMS; ++consumed) {
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &empty);
|
||||
|
||||
<a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(pt, &mutex);
|
||||
consume_item(get_from_buffer());
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &mutex);
|
||||
|
||||
<a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(pt, &full);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
|
||||
<a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(driver_thread(<span class="keyword">struct</span> pt *pt))
|
||||
{
|
||||
<span class="keyword">static</span> <span class="keyword">struct </span>pt pt_producer, pt_consumer;
|
||||
|
||||
<a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">PT_BEGIN</a>(pt);
|
||||
|
||||
<a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(&empty, 0);
|
||||
<a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(&full, BUFSIZE);
|
||||
<a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(&mutex, 1);
|
||||
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt_producer);
|
||||
<a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">PT_INIT</a>(&pt_consumer);
|
||||
|
||||
<a class="code" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">PT_WAIT_THREAD</a>(pt, producer(&pt_producer) &
|
||||
consumer(&pt_consumer));
|
||||
|
||||
<a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">PT_END</a>(pt);
|
||||
}
|
||||
</pre></div><p>
|
||||
The program uses three protothreads: one protothread that implements the consumer, one thread that implements the producer, and one protothread that drives the two other protothreads. The program uses three semaphores: "full", "empty" and "mutex". The "mutex" semaphore is used to provide mutual exclusion for the buffer, the "empty" semaphore is used to block the consumer is the buffer is empty, and the "full" semaphore is used to block the producer is the buffer is full.<p>
|
||||
The "driver_thread" holds two protothread state variables, "pt_producer" and "pt_consumer". It is important to note that both these variables are declared as <em>static</em>. If the static keyword is not used, both variables are stored on the stack. Since protothreads do not store the stack, these variables may be overwritten during a protothread wait operation. Similarly, both the "consumer" and "producer" protothreads declare their local variables as static, to avoid them being stored on the stack.
|
||||
<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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00012.html">pt-sem.h</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Couting semaphores implemented on 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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00006.html">pt_sem</a></td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">PT_SEM_INIT</a>(s, c)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a semaphore. <a href="#gd7089c5dc86f12019f0361d82a75b04b"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#g386ff87a52a840512906f2940e229e2e">PT_SEM_WAIT</a>(<a class="el" href="a00005.html">pt</a>, s)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Wait for a semaphore. <a href="#g386ff87a52a840512906f2940e229e2e"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">PT_SEM_SIGNAL</a>(<a class="el" href="a00005.html">pt</a>, s)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Signal a semaphore. <a href="#g1eaaf4d9d75e24582acc6440d7085f19"></a><br></td></tr>
|
||||
</table>
|
||||
<hr><h2>Define Documentation</h2>
|
||||
<a class="anchor" name="gd7089c5dc86f12019f0361d82a75b04b"></a><!-- doxytag: member="pt-sem.h::PT_SEM_INIT" ref="gd7089c5dc86f12019f0361d82a75b04b" args="(s, c)" --><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_SEM_INIT </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top">s, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>c </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Initialize a semaphore.
|
||||
<p>
|
||||
This macro initializes a semaphore with a value for the counter. Internally, the semaphores use an "unsigned int" to represent the counter, and therefore the "count" argument should be within range of an unsigned int.<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>s</em> </td><td>(struct <a class="el" href="a00006.html">pt_sem</a> *) A pointer to the <a class="el" href="a00006.html">pt_sem</a> struct representing the semaphore</td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>c</em> </td><td>(unsigned int) The initial count of the semaphore. </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00021.html#l00183">183</a> of file <a class="el" href="a00021.html">pt-sem.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="anchor" name="g1eaaf4d9d75e24582acc6440d7085f19"></a><!-- doxytag: member="pt-sem.h::PT_SEM_SIGNAL" ref="g1eaaf4d9d75e24582acc6440d7085f19" args="(pt, s)" --><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_SEM_SIGNAL </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>s </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Signal a semaphore.
|
||||
<p>
|
||||
This macro carries out the "signal" operation on the semaphore. The signal operation increments the counter inside the semaphore, which eventually will cause waiting protothreads to continue executing.<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> </td><td>(struct pt *) A pointer to the protothread (struct pt) in which the operation is executed.</td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>s</em> </td><td>(struct <a class="el" href="a00006.html">pt_sem</a> *) A pointer to the <a class="el" href="a00006.html">pt_sem</a> struct representing the semaphore </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00021.html#l00222">222</a> of file <a class="el" href="a00021.html">pt-sem.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="anchor" name="g386ff87a52a840512906f2940e229e2e"></a><!-- doxytag: member="pt-sem.h::PT_SEM_WAIT" ref="g386ff87a52a840512906f2940e229e2e" args="(pt, s)" --><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_SEM_WAIT </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top"><a class="el" href="a00005.html">pt</a>, <tr>
|
||||
<td class="md" nowrap align="right"></td>
|
||||
<td class="md"></td>
|
||||
<td class="md" nowrap>s </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Wait for a semaphore.
|
||||
<p>
|
||||
This macro carries out the "wait" operation on the semaphore. The wait operation causes the protothread to block while the counter is zero. When the counter reaches a value larger than zero, the protothread will continue.<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> </td><td>(struct pt *) A pointer to the protothread (struct pt) in which the operation is executed.</td></tr>
|
||||
<tr><td valign="top"></td><td valign="top"><em>s</em> </td><td>(struct <a class="el" href="a00006.html">pt_sem</a> *) A pointer to the <a class="el" href="a00006.html">pt_sem</a> struct representing the semaphore </td></tr>
|
||||
</table>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00021.html#l00201">201</a> of file <a class="el" href="a00021.html">pt-sem.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,226 @@
|
|||
<!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.4: Local continuations</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<h1>Local continuations<br>
|
||||
<small>
|
||||
[<a class="el" href="a00014.html">Protothreads</a>]</small>
|
||||
</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
|
||||
Local continuations form the basis for implementing protothreads.
|
||||
<p>
|
||||
A local continuation can be <em>set</em> in a specific function to capture the state of the function. After a local continuation has been set can be <em>resumed</em> in order to restore the state of the function at the point where the local continuation was set.
|
||||
<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 </td><td class="memItemRight" valign="bottom"><a class="el" href="a00011.html">lc.h</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Local continuations. <br></td></tr>
|
||||
|
||||
<p>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">file </td><td class="memItemRight" valign="bottom"><a class="el" href="a00010.html">lc-switch.h</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Implementation of local continuations based on switch() statment. <br></td></tr>
|
||||
|
||||
<p>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">file </td><td class="memItemRight" valign="bottom"><a class="el" href="a00009.html">lc-addrlabels.h</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Implementation of local continuations based on the "Labels as values" feature of gcc. <br></td></tr>
|
||||
|
||||
<p>
|
||||
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76">LC_INIT</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a local continuation. <a href="#g9ca9d0fef02b9c5d93bed2834e7aeb76"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341">LC_SET</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set a local continuation. <a href="#gfb1d5e671e40464a7a7bda589b5d4341"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3">LC_RESUME</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Resume a local continuation. <a href="#g33dad6011c98dfeb4e64fee1d6892cb3"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g3d76802e55349cc8bf74f286ced203c3">LC_END</a>(lc)</td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">Mark the end of local continuation usage. <a href="#g3d76802e55349cc8bf74f286ced203c3"></a><br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2c1bb4fa6d7a6ff951a41c73fc721109"></a><!-- doxytag: member="lc::LC_INIT" ref="g2c1bb4fa6d7a6ff951a41c73fc721109" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">LC_INIT</a>(s) s = 0;</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g1ec8b8f4710dce1fa7fb87d3a31541ae"></a><!-- doxytag: member="lc::LC_RESUME" ref="g1ec8b8f4710dce1fa7fb87d3a31541ae" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">LC_RESUME</a>(s) switch(s) { case 0:</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gd8eec328a4868d767f0c00c8d1c6cfc1"></a><!-- doxytag: member="lc::LC_SET" ref="gd8eec328a4868d767f0c00c8d1c6cfc1" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">LC_SET</a>(s) s = __LINE__; case __LINE__:</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gca51ceb2f5d855dfde55bcedf8d3b92d"></a><!-- doxytag: member="lc::LC_END" ref="gca51ceb2f5d855dfde55bcedf8d3b92d" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">LC_END</a>(s) }</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2c1bb4fa6d7a6ff951a41c73fc721109"></a><!-- doxytag: member="lc::LC_INIT" ref="g2c1bb4fa6d7a6ff951a41c73fc721109" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">LC_INIT</a>(s) s = NULL</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g1ec8b8f4710dce1fa7fb87d3a31541ae"></a><!-- doxytag: member="lc::LC_RESUME" ref="g1ec8b8f4710dce1fa7fb87d3a31541ae" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">LC_RESUME</a>(s)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g6e1e879e172e2d8838e5f567dac8918c"></a><!-- doxytag: member="lc::LC_CONCAT2" ref="g6e1e879e172e2d8838e5f567dac8918c" args="(s1, s2)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g6e1e879e172e2d8838e5f567dac8918c">LC_CONCAT2</a>(s1, s2) s1##s2</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2b1f9b9fe8b6895b156f0af10538971c"></a><!-- doxytag: member="lc::LC_CONCAT" ref="g2b1f9b9fe8b6895b156f0af10538971c" args="(s1, s2)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2b1f9b9fe8b6895b156f0af10538971c">LC_CONCAT</a>(s1, s2) LC_CONCAT2(s1, s2)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gd8eec328a4868d767f0c00c8d1c6cfc1"></a><!-- doxytag: member="lc::LC_SET" ref="gd8eec328a4868d767f0c00c8d1c6cfc1" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">LC_SET</a>(s)</td></tr>
|
||||
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gca51ceb2f5d855dfde55bcedf8d3b92d"></a><!-- doxytag: member="lc::LC_END" ref="gca51ceb2f5d855dfde55bcedf8d3b92d" args="(s)" -->
|
||||
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">LC_END</a>(s)</td></tr>
|
||||
|
||||
<tr><td colspan="2"><br><h2>Typedefs</h2></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="gfad6704adb116cc16edb80f744e7239d"></a><!-- doxytag: member="lc::lc_t" ref="gfad6704adb116cc16edb80f744e7239d" args="" -->
|
||||
typedef unsigned short </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc_t</a></td></tr>
|
||||
|
||||
<tr><td class="mdescLeft"> </td><td class="mdescRight">The local continuation type. <br></td></tr>
|
||||
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="g2bdc4b7b4038454a79f1b2a94a6d2a98"></a><!-- doxytag: member="lc::lc_t" ref="g2bdc4b7b4038454a79f1b2a94a6d2a98" args="" -->
|
||||
typedef void * </td><td class="memItemRight" valign="bottom"><a class="el" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">lc_t</a></td></tr>
|
||||
|
||||
</table>
|
||||
<hr><h2>Define Documentation</h2>
|
||||
<a class="anchor" name="g3d76802e55349cc8bf74f286ced203c3"></a><!-- doxytag: member="lc.h::LC_END" ref="g3d76802e55349cc8bf74f286ced203c3" args="(lc)" --><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 LC_END </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top">lc </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Mark the end of local continuation usage.
|
||||
<p>
|
||||
The end operation signifies that local continuations should not be used any more in the function. This operation is not needed for most implementations of local continuation, but is required by a few implementations.
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00020.html#l00108">108</a> of file <a class="el" href="a00020.html">lc.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="anchor" name="g9ca9d0fef02b9c5d93bed2834e7aeb76"></a><!-- doxytag: member="lc.h::LC_INIT" ref="g9ca9d0fef02b9c5d93bed2834e7aeb76" args="(lc)" --><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 LC_INIT </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top">lc </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Initialize a local continuation.
|
||||
<p>
|
||||
This operation initializes the local continuation, thereby unsetting any previously set continuation state.
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00020.html#l00071">71</a> of file <a class="el" href="a00020.html">lc.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="anchor" name="g33dad6011c98dfeb4e64fee1d6892cb3"></a><!-- doxytag: member="lc.h::LC_RESUME" ref="g33dad6011c98dfeb4e64fee1d6892cb3" args="(lc)" --><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 LC_RESUME </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top">lc </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Resume a local continuation.
|
||||
<p>
|
||||
The resume operation resumes a previously set local continuation, thus restoring the state in which the function was when the local continuation was set. If the local continuation has not been previously set, the resume operation does nothing.
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00020.html#l00096">96</a> of file <a class="el" href="a00020.html">lc.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a class="anchor" name="gfb1d5e671e40464a7a7bda589b5d4341"></a><!-- doxytag: member="lc.h::LC_SET" ref="gfb1d5e671e40464a7a7bda589b5d4341" args="(lc)" --><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 LC_SET </td>
|
||||
<td class="md" valign="top">( </td>
|
||||
<td class="md" nowrap valign="top">lc </td>
|
||||
<td class="mdname1" valign="top" nowrap> </td>
|
||||
<td class="md" valign="top"> ) </td>
|
||||
<td class="md" nowrap></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="5" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<p>
|
||||
Set a local continuation.
|
||||
<p>
|
||||
The set operation saves the state of the function at the point where the operation is executed. As far as the set operation is concerned, the state of the function does <b>not</b> include the call-stack or local (automatic) variables, but only the program counter and such CPU registers that needs to be saved.
|
||||
<p>
|
||||
Definition at line <a class="el" href="a00020.html#l00084">84</a> of file <a class="el" href="a00020.html">lc.h</a>. </td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,109 @@
|
|||
<!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.4: lc-addrlabels.h 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.4.6 -->
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc-addrlabels.h</h1><a href="a00009.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved.</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> *</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * are met:</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * may be used to endorse or promote products derived from this software</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * without specific prior written permission.</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
|
||||
<a name="l00022"></a>00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
|
||||
<a name="l00023"></a>00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
|
||||
<a name="l00024"></a>00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
|
||||
<a name="l00025"></a>00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
|
||||
<a name="l00026"></a>00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
|
||||
<a name="l00027"></a>00027 <span class="comment"> * SUCH DAMAGE.</span>
|
||||
<a name="l00028"></a>00028 <span class="comment"> *</span>
|
||||
<a name="l00029"></a>00029 <span class="comment"> * This file is part of the Contiki operating system.</span>
|
||||
<a name="l00030"></a>00030 <span class="comment"> *</span>
|
||||
<a name="l00031"></a>00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00032"></a>00032 <span class="comment"> *</span>
|
||||
<a name="l00033"></a>00033 <span class="comment"> * $Id: lc-addrlabels.h,v 1.4 2006/06/03 11:29:43 adam Exp $</span>
|
||||
<a name="l00034"></a>00034 <span class="comment"> */</span>
|
||||
<a name="l00035"></a>00035 <span class="comment"></span>
|
||||
<a name="l00036"></a>00036 <span class="comment">/**</span>
|
||||
<a name="l00037"></a>00037 <span class="comment"> * \addtogroup lc</span>
|
||||
<a name="l00038"></a>00038 <span class="comment"> * @{</span>
|
||||
<a name="l00039"></a>00039 <span class="comment"> */</span>
|
||||
<a name="l00040"></a>00040 <span class="comment"></span>
|
||||
<a name="l00041"></a>00041 <span class="comment">/**</span>
|
||||
<a name="l00042"></a>00042 <span class="comment"> * \file</span>
|
||||
<a name="l00043"></a>00043 <span class="comment"> * Implementation of local continuations based on the "Labels as</span>
|
||||
<a name="l00044"></a>00044 <span class="comment"> * values" feature of gcc</span>
|
||||
<a name="l00045"></a>00045 <span class="comment"> * \author</span>
|
||||
<a name="l00046"></a>00046 <span class="comment"> * Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00047"></a>00047 <span class="comment"> *</span>
|
||||
<a name="l00048"></a>00048 <span class="comment"> * This implementation of local continuations is based on a special</span>
|
||||
<a name="l00049"></a>00049 <span class="comment"> * feature of the GCC C compiler called "labels as values". This</span>
|
||||
<a name="l00050"></a>00050 <span class="comment"> * feature allows assigning pointers with the address of the code</span>
|
||||
<a name="l00051"></a>00051 <span class="comment"> * corresponding to a particular C label.</span>
|
||||
<a name="l00052"></a>00052 <span class="comment"> *</span>
|
||||
<a name="l00053"></a>00053 <span class="comment"> * For more information, see the GCC documentation:</span>
|
||||
<a name="l00054"></a>00054 <span class="comment"> * http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html</span>
|
||||
<a name="l00055"></a>00055 <span class="comment"> *</span>
|
||||
<a name="l00056"></a>00056 <span class="comment"> */</span>
|
||||
<a name="l00057"></a>00057
|
||||
<a name="l00058"></a>00058 <span class="preprocessor">#ifndef __LC_ADDRLABELS_H__</span>
|
||||
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#define __LC_ADDRLABELS_H__</span>
|
||||
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00061"></a>00061 <span class="comment">/** \hideinitializer */</span>
|
||||
<a name="l00062"></a><a class="code" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">00062</a> <span class="keyword">typedef</span> <span class="keywordtype">void</span> * <a class="code" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc_t</a>;
|
||||
<a name="l00063"></a>00063
|
||||
<a name="l00064"></a><a class="code" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">00064</a> <span class="preprocessor">#define LC_INIT(s) s = NULL</span>
|
||||
<a name="l00065"></a>00065 <span class="preprocessor"></span>
|
||||
<a name="l00066"></a><a class="code" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">00066</a> <span class="preprocessor">#define LC_RESUME(s) \</span>
|
||||
<a name="l00067"></a>00067 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00068"></a>00068 <span class="preprocessor"> if(s != NULL) { \</span>
|
||||
<a name="l00069"></a>00069 <span class="preprocessor"> goto *s; \</span>
|
||||
<a name="l00070"></a>00070 <span class="preprocessor"> } \</span>
|
||||
<a name="l00071"></a>00071 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00072"></a>00072 <span class="preprocessor"></span>
|
||||
<a name="l00073"></a><a class="code" href="a00017.html#g6e1e879e172e2d8838e5f567dac8918c">00073</a> <span class="preprocessor">#define LC_CONCAT2(s1, s2) s1##s2</span>
|
||||
<a name="l00074"></a><a class="code" href="a00017.html#g2b1f9b9fe8b6895b156f0af10538971c">00074</a> <span class="preprocessor"></span><span class="preprocessor">#define LC_CONCAT(s1, s2) LC_CONCAT2(s1, s2)</span>
|
||||
<a name="l00075"></a>00075 <span class="preprocessor"></span>
|
||||
<a name="l00076"></a><a class="code" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">00076</a> <span class="preprocessor">#define LC_SET(s) \</span>
|
||||
<a name="l00077"></a>00077 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00078"></a>00078 <span class="preprocessor"> LC_CONCAT(LC_LABEL, __LINE__): \</span>
|
||||
<a name="l00079"></a>00079 <span class="preprocessor"> (s) = &&LC_CONCAT(LC_LABEL, __LINE__); \</span>
|
||||
<a name="l00080"></a>00080 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00081"></a>00081 <span class="preprocessor"></span>
|
||||
<a name="l00082"></a><a class="code" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">00082</a> <span class="preprocessor">#define LC_END(s)</span>
|
||||
<a name="l00083"></a>00083 <span class="preprocessor"></span>
|
||||
<a name="l00084"></a>00084 <span class="preprocessor">#endif </span><span class="comment">/* __LC_ADDRLABELS_H__ */</span>
|
||||
<a name="l00085"></a>00085 <span class="comment">/** @} */</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,100 @@
|
|||
<!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.4: lc-switch.h 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.4.6 -->
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc-switch.h</h1><a href="a00010.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved.</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> *</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * are met:</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * may be used to endorse or promote products derived from this software</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * without specific prior written permission.</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
|
||||
<a name="l00022"></a>00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
|
||||
<a name="l00023"></a>00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
|
||||
<a name="l00024"></a>00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
|
||||
<a name="l00025"></a>00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
|
||||
<a name="l00026"></a>00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
|
||||
<a name="l00027"></a>00027 <span class="comment"> * SUCH DAMAGE.</span>
|
||||
<a name="l00028"></a>00028 <span class="comment"> *</span>
|
||||
<a name="l00029"></a>00029 <span class="comment"> * This file is part of the Contiki operating system.</span>
|
||||
<a name="l00030"></a>00030 <span class="comment"> *</span>
|
||||
<a name="l00031"></a>00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00032"></a>00032 <span class="comment"> *</span>
|
||||
<a name="l00033"></a>00033 <span class="comment"> * $Id: lc-switch.h,v 1.4 2006/06/03 11:29:43 adam Exp $</span>
|
||||
<a name="l00034"></a>00034 <span class="comment"> */</span>
|
||||
<a name="l00035"></a>00035 <span class="comment"></span>
|
||||
<a name="l00036"></a>00036 <span class="comment">/**</span>
|
||||
<a name="l00037"></a>00037 <span class="comment"> * \addtogroup lc</span>
|
||||
<a name="l00038"></a>00038 <span class="comment"> * @{</span>
|
||||
<a name="l00039"></a>00039 <span class="comment"> */</span>
|
||||
<a name="l00040"></a>00040 <span class="comment"></span>
|
||||
<a name="l00041"></a>00041 <span class="comment">/**</span>
|
||||
<a name="l00042"></a>00042 <span class="comment"> * \file</span>
|
||||
<a name="l00043"></a>00043 <span class="comment"> * Implementation of local continuations based on switch() statment</span>
|
||||
<a name="l00044"></a>00044 <span class="comment"> * \author Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00045"></a>00045 <span class="comment"> *</span>
|
||||
<a name="l00046"></a>00046 <span class="comment"> * This implementation of local continuations uses the C switch()</span>
|
||||
<a name="l00047"></a>00047 <span class="comment"> * statement to resume execution of a function somewhere inside the</span>
|
||||
<a name="l00048"></a>00048 <span class="comment"> * function's body. The implementation is based on the fact that</span>
|
||||
<a name="l00049"></a>00049 <span class="comment"> * switch() statements are able to jump directly into the bodies of</span>
|
||||
<a name="l00050"></a>00050 <span class="comment"> * control structures such as if() or while() statmenets.</span>
|
||||
<a name="l00051"></a>00051 <span class="comment"> *</span>
|
||||
<a name="l00052"></a>00052 <span class="comment"> * This implementation borrows heavily from Simon Tatham's coroutines</span>
|
||||
<a name="l00053"></a>00053 <span class="comment"> * implementation in C:</span>
|
||||
<a name="l00054"></a>00054 <span class="comment"> * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html</span>
|
||||
<a name="l00055"></a>00055 <span class="comment"> */</span>
|
||||
<a name="l00056"></a>00056
|
||||
<a name="l00057"></a>00057 <span class="preprocessor">#ifndef __LC_SWITCH_H__</span>
|
||||
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#define __LC_SWITCH_H__</span>
|
||||
<a name="l00059"></a>00059 <span class="preprocessor"></span>
|
||||
<a name="l00060"></a>00060 <span class="comment">/* WARNING! lc implementation using switch() does not work if an</span>
|
||||
<a name="l00061"></a>00061 <span class="comment"> LC_SET() is done within another switch() statement! */</span>
|
||||
<a name="l00062"></a>00062 <span class="comment"></span>
|
||||
<a name="l00063"></a>00063 <span class="comment">/** \hideinitializer */</span>
|
||||
<a name="l00064"></a><a class="code" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">00064</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc_t</a>;
|
||||
<a name="l00065"></a>00065
|
||||
<a name="l00066"></a><a class="code" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">00066</a> <span class="preprocessor">#define LC_INIT(s) s = 0;</span>
|
||||
<a name="l00067"></a>00067 <span class="preprocessor"></span>
|
||||
<a name="l00068"></a><a class="code" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">00068</a> <span class="preprocessor">#define LC_RESUME(s) switch(s) { case 0:</span>
|
||||
<a name="l00069"></a>00069 <span class="preprocessor"></span>
|
||||
<a name="l00070"></a><a class="code" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">00070</a> <span class="preprocessor">#define LC_SET(s) s = __LINE__; case __LINE__:</span>
|
||||
<a name="l00071"></a>00071 <span class="preprocessor"></span>
|
||||
<a name="l00072"></a><a class="code" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">00072</a> <span class="preprocessor">#define LC_END(s) }</span>
|
||||
<a name="l00073"></a>00073 <span class="preprocessor"></span>
|
||||
<a name="l00074"></a>00074 <span class="preprocessor">#endif </span><span class="comment">/* __LC_SWITCH_H__ */</span>
|
||||
<a name="l00075"></a>00075 <span class="comment"></span>
|
||||
<a name="l00076"></a>00076 <span class="comment">/** @} */</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,156 @@
|
|||
<!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.4: lc.h 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.4.6 -->
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>lc.h</h1><a href="a00011.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved. </span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> *</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without </span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions </span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * are met: </span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright </span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer. </span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright </span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the </span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * documentation and/or other materials provided with the distribution. </span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors </span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * may be used to endorse or promote products derived from this software </span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * without specific prior written permission. </span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND </span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE </span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE </span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </span>
|
||||
<a name="l00022"></a>00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS </span>
|
||||
<a name="l00023"></a>00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) </span>
|
||||
<a name="l00024"></a>00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT </span>
|
||||
<a name="l00025"></a>00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY </span>
|
||||
<a name="l00026"></a>00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF </span>
|
||||
<a name="l00027"></a>00027 <span class="comment"> * SUCH DAMAGE. </span>
|
||||
<a name="l00028"></a>00028 <span class="comment"> *</span>
|
||||
<a name="l00029"></a>00029 <span class="comment"> * This file is part of the protothreads library.</span>
|
||||
<a name="l00030"></a>00030 <span class="comment"> * </span>
|
||||
<a name="l00031"></a>00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00032"></a>00032 <span class="comment"> *</span>
|
||||
<a name="l00033"></a>00033 <span class="comment"> * $Id: lc.h,v 1.2 2005/02/24 10:36:59 adam Exp $</span>
|
||||
<a name="l00034"></a>00034 <span class="comment"> */</span>
|
||||
<a name="l00035"></a>00035 <span class="comment"></span>
|
||||
<a name="l00036"></a>00036 <span class="comment">/**</span>
|
||||
<a name="l00037"></a>00037 <span class="comment"> * \addtogroup pt</span>
|
||||
<a name="l00038"></a>00038 <span class="comment"> * @{</span>
|
||||
<a name="l00039"></a>00039 <span class="comment"> */</span>
|
||||
<a name="l00040"></a>00040 <span class="comment"></span>
|
||||
<a name="l00041"></a>00041 <span class="comment">/**</span>
|
||||
<a name="l00042"></a>00042 <span class="comment"> * \defgroup lc Local continuations</span>
|
||||
<a name="l00043"></a>00043 <span class="comment"> * @{</span>
|
||||
<a name="l00044"></a>00044 <span class="comment"> *</span>
|
||||
<a name="l00045"></a>00045 <span class="comment"> * Local continuations form the basis for implementing protothreads. A</span>
|
||||
<a name="l00046"></a>00046 <span class="comment"> * local continuation can be <i>set</i> in a specific function to</span>
|
||||
<a name="l00047"></a>00047 <span class="comment"> * capture the state of the function. After a local continuation has</span>
|
||||
<a name="l00048"></a>00048 <span class="comment"> * been set can be <i>resumed</i> in order to restore the state of the</span>
|
||||
<a name="l00049"></a>00049 <span class="comment"> * function at the point where the local continuation was set.</span>
|
||||
<a name="l00050"></a>00050 <span class="comment"> *</span>
|
||||
<a name="l00051"></a>00051 <span class="comment"> *</span>
|
||||
<a name="l00052"></a>00052 <span class="comment"> */</span>
|
||||
<a name="l00053"></a>00053 <span class="comment"></span>
|
||||
<a name="l00054"></a>00054 <span class="comment">/**</span>
|
||||
<a name="l00055"></a>00055 <span class="comment"> * \file lc.h</span>
|
||||
<a name="l00056"></a>00056 <span class="comment"> * Local continuations</span>
|
||||
<a name="l00057"></a>00057 <span class="comment"> * \author</span>
|
||||
<a name="l00058"></a>00058 <span class="comment"> * Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00059"></a>00059 <span class="comment"> *</span>
|
||||
<a name="l00060"></a>00060 <span class="comment"> */</span>
|
||||
<a name="l00061"></a>00061
|
||||
<a name="l00062"></a>00062 <span class="preprocessor">#ifdef DOXYGEN</span>
|
||||
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="comment">/**</span>
|
||||
<a name="l00064"></a>00064 <span class="comment"> * Initialize a local continuation.</span>
|
||||
<a name="l00065"></a>00065 <span class="comment"> *</span>
|
||||
<a name="l00066"></a>00066 <span class="comment"> * This operation initializes the local continuation, thereby</span>
|
||||
<a name="l00067"></a>00067 <span class="comment"> * unsetting any previously set continuation state.</span>
|
||||
<a name="l00068"></a>00068 <span class="comment"> *</span>
|
||||
<a name="l00069"></a>00069 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00070"></a>00070 <span class="comment"> */</span>
|
||||
<a name="l00071"></a><a class="code" href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76">00071</a> <span class="preprocessor">#define LC_INIT(lc)</span>
|
||||
<a name="l00072"></a>00072 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00073"></a>00073 <span class="comment">/**</span>
|
||||
<a name="l00074"></a>00074 <span class="comment"> * Set a local continuation.</span>
|
||||
<a name="l00075"></a>00075 <span class="comment"> *</span>
|
||||
<a name="l00076"></a>00076 <span class="comment"> * The set operation saves the state of the function at the point</span>
|
||||
<a name="l00077"></a>00077 <span class="comment"> * where the operation is executed. As far as the set operation is</span>
|
||||
<a name="l00078"></a>00078 <span class="comment"> * concerned, the state of the function does <b>not</b> include the</span>
|
||||
<a name="l00079"></a>00079 <span class="comment"> * call-stack or local (automatic) variables, but only the program</span>
|
||||
<a name="l00080"></a>00080 <span class="comment"> * counter and such CPU registers that needs to be saved.</span>
|
||||
<a name="l00081"></a>00081 <span class="comment"> *</span>
|
||||
<a name="l00082"></a>00082 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00083"></a>00083 <span class="comment"> */</span>
|
||||
<a name="l00084"></a><a class="code" href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341">00084</a> <span class="preprocessor">#define LC_SET(lc)</span>
|
||||
<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00086"></a>00086 <span class="comment">/**</span>
|
||||
<a name="l00087"></a>00087 <span class="comment"> * Resume a local continuation.</span>
|
||||
<a name="l00088"></a>00088 <span class="comment"> *</span>
|
||||
<a name="l00089"></a>00089 <span class="comment"> * The resume operation resumes a previously set local continuation, thus</span>
|
||||
<a name="l00090"></a>00090 <span class="comment"> * restoring the state in which the function was when the local</span>
|
||||
<a name="l00091"></a>00091 <span class="comment"> * continuation was set. If the local continuation has not been</span>
|
||||
<a name="l00092"></a>00092 <span class="comment"> * previously set, the resume operation does nothing.</span>
|
||||
<a name="l00093"></a>00093 <span class="comment"> *</span>
|
||||
<a name="l00094"></a>00094 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00095"></a>00095 <span class="comment"> */</span>
|
||||
<a name="l00096"></a><a class="code" href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3">00096</a> <span class="preprocessor">#define LC_RESUME(lc)</span>
|
||||
<a name="l00097"></a>00097 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00098"></a>00098 <span class="comment">/**</span>
|
||||
<a name="l00099"></a>00099 <span class="comment"> * Mark the end of local continuation usage.</span>
|
||||
<a name="l00100"></a>00100 <span class="comment"> *</span>
|
||||
<a name="l00101"></a>00101 <span class="comment"> * The end operation signifies that local continuations should not be</span>
|
||||
<a name="l00102"></a>00102 <span class="comment"> * used any more in the function. This operation is not needed for</span>
|
||||
<a name="l00103"></a>00103 <span class="comment"> * most implementations of local continuation, but is required by a</span>
|
||||
<a name="l00104"></a>00104 <span class="comment"> * few implementations.</span>
|
||||
<a name="l00105"></a>00105 <span class="comment"> *</span>
|
||||
<a name="l00106"></a>00106 <span class="comment"> * \hideinitializer </span>
|
||||
<a name="l00107"></a>00107 <span class="comment"> */</span>
|
||||
<a name="l00108"></a><a class="code" href="a00017.html#g3d76802e55349cc8bf74f286ced203c3">00108</a> <span class="preprocessor">#define LC_END(lc)</span>
|
||||
<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00110"></a>00110 <span class="comment">/**</span>
|
||||
<a name="l00111"></a>00111 <span class="comment"> * \var typedef lc_t;</span>
|
||||
<a name="l00112"></a>00112 <span class="comment"> *</span>
|
||||
<a name="l00113"></a>00113 <span class="comment"> * The local continuation type.</span>
|
||||
<a name="l00114"></a>00114 <span class="comment"> *</span>
|
||||
<a name="l00115"></a>00115 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00116"></a>00116 <span class="comment"> */</span>
|
||||
<a name="l00117"></a>00117 <span class="preprocessor">#endif </span><span class="comment">/* DOXYGEN */</span>
|
||||
<a name="l00118"></a>00118
|
||||
<a name="l00119"></a>00119 <span class="preprocessor">#ifndef __LC_H__</span>
|
||||
<a name="l00120"></a>00120 <span class="preprocessor"></span><span class="preprocessor">#define __LC_H__</span>
|
||||
<a name="l00121"></a>00121 <span class="preprocessor"></span>
|
||||
<a name="l00122"></a>00122
|
||||
<a name="l00123"></a>00123 <span class="preprocessor">#ifdef LC_INCLUDE</span>
|
||||
<a name="l00124"></a>00124 <span class="preprocessor"></span><span class="preprocessor">#include LC_INCLUDE</span>
|
||||
<a name="l00125"></a>00125 <span class="preprocessor"></span><span class="preprocessor">#else</span>
|
||||
<a name="l00126"></a>00126 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="a00010.html">lc-switch.h</a>"</span>
|
||||
<a name="l00127"></a>00127 <span class="preprocessor">#endif </span><span class="comment">/* LC_INCLUDE */</span>
|
||||
<a name="l00128"></a>00128
|
||||
<a name="l00129"></a>00129 <span class="preprocessor">#endif </span><span class="comment">/* __LC_H__ */</span>
|
||||
<a name="l00130"></a>00130 <span class="comment"></span>
|
||||
<a name="l00131"></a>00131 <span class="comment">/** @} */</span><span class="comment"></span>
|
||||
<a name="l00132"></a>00132 <span class="comment">/** @} */</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,252 @@
|
|||
<!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.4: pt-sem.h 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.4.6 -->
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt-sem.h</h1><a href="a00012.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2004, Swedish Institute of Computer Science.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved. </span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> *</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without </span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions </span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * are met: </span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright </span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer. </span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright </span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the </span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * documentation and/or other materials provided with the distribution. </span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors </span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * may be used to endorse or promote products derived from this software </span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * without specific prior written permission. </span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND </span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE </span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE </span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </span>
|
||||
<a name="l00022"></a>00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS </span>
|
||||
<a name="l00023"></a>00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) </span>
|
||||
<a name="l00024"></a>00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT </span>
|
||||
<a name="l00025"></a>00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY </span>
|
||||
<a name="l00026"></a>00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF </span>
|
||||
<a name="l00027"></a>00027 <span class="comment"> * SUCH DAMAGE. </span>
|
||||
<a name="l00028"></a>00028 <span class="comment"> *</span>
|
||||
<a name="l00029"></a>00029 <span class="comment"> * This file is part of the protothreads library.</span>
|
||||
<a name="l00030"></a>00030 <span class="comment"> * </span>
|
||||
<a name="l00031"></a>00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00032"></a>00032 <span class="comment"> *</span>
|
||||
<a name="l00033"></a>00033 <span class="comment"> * $Id: pt-sem.h,v 1.2 2005/02/24 10:36:59 adam Exp $</span>
|
||||
<a name="l00034"></a>00034 <span class="comment"> */</span>
|
||||
<a name="l00035"></a>00035 <span class="comment"></span>
|
||||
<a name="l00036"></a>00036 <span class="comment">/**</span>
|
||||
<a name="l00037"></a>00037 <span class="comment"> * \addtogroup pt</span>
|
||||
<a name="l00038"></a>00038 <span class="comment"> * @{</span>
|
||||
<a name="l00039"></a>00039 <span class="comment"> */</span>
|
||||
<a name="l00040"></a>00040 <span class="comment"></span>
|
||||
<a name="l00041"></a>00041 <span class="comment">/**</span>
|
||||
<a name="l00042"></a>00042 <span class="comment"> * \defgroup ptsem Protothread semaphores</span>
|
||||
<a name="l00043"></a>00043 <span class="comment"> * @{</span>
|
||||
<a name="l00044"></a>00044 <span class="comment"> *</span>
|
||||
<a name="l00045"></a>00045 <span class="comment"> * This module implements counting semaphores on top of</span>
|
||||
<a name="l00046"></a>00046 <span class="comment"> * protothreads. Semaphores are a synchronization primitive that</span>
|
||||
<a name="l00047"></a>00047 <span class="comment"> * provide two operations: "wait" and "signal". The "wait" operation</span>
|
||||
<a name="l00048"></a>00048 <span class="comment"> * checks the semaphore counter and blocks the thread if the counter</span>
|
||||
<a name="l00049"></a>00049 <span class="comment"> * is zero. The "signal" operation increases the semaphore counter but</span>
|
||||
<a name="l00050"></a>00050 <span class="comment"> * does not block. If another thread has blocked waiting for the</span>
|
||||
<a name="l00051"></a>00051 <span class="comment"> * semaphore that is signalled, the blocked thread will become</span>
|
||||
<a name="l00052"></a>00052 <span class="comment"> * runnable again.</span>
|
||||
<a name="l00053"></a>00053 <span class="comment"> *</span>
|
||||
<a name="l00054"></a>00054 <span class="comment"> * Semaphores can be used to implement other, more structured,</span>
|
||||
<a name="l00055"></a>00055 <span class="comment"> * synchronization primitives such as monitors and message</span>
|
||||
<a name="l00056"></a>00056 <span class="comment"> * queues/bounded buffers (see below).</span>
|
||||
<a name="l00057"></a>00057 <span class="comment"> *</span>
|
||||
<a name="l00058"></a>00058 <span class="comment"> * The following example shows how the producer-consumer problem, also</span>
|
||||
<a name="l00059"></a>00059 <span class="comment"> * known as the bounded buffer problem, can be solved using</span>
|
||||
<a name="l00060"></a>00060 <span class="comment"> * protothreads and semaphores. Notes on the program follow after the</span>
|
||||
<a name="l00061"></a>00061 <span class="comment"> * example.</span>
|
||||
<a name="l00062"></a>00062 <span class="comment"> *</span>
|
||||
<a name="l00063"></a>00063 <span class="comment"> \code</span>
|
||||
<a name="l00064"></a>00064 <span class="comment">#include "pt-sem.h"</span>
|
||||
<a name="l00065"></a>00065 <span class="comment"></span>
|
||||
<a name="l00066"></a>00066 <span class="comment">#define NUM_ITEMS 32</span>
|
||||
<a name="l00067"></a>00067 <span class="comment">#define BUFSIZE 8</span>
|
||||
<a name="l00068"></a>00068 <span class="comment"></span>
|
||||
<a name="l00069"></a>00069 <span class="comment">static struct pt_sem mutex, full, empty;</span>
|
||||
<a name="l00070"></a>00070 <span class="comment"></span>
|
||||
<a name="l00071"></a>00071 <span class="comment">PT_THREAD(producer(struct pt *pt))</span>
|
||||
<a name="l00072"></a>00072 <span class="comment">{</span>
|
||||
<a name="l00073"></a>00073 <span class="comment"> static int produced;</span>
|
||||
<a name="l00074"></a>00074 <span class="comment"> </span>
|
||||
<a name="l00075"></a>00075 <span class="comment"> PT_BEGIN(pt);</span>
|
||||
<a name="l00076"></a>00076 <span class="comment"> </span>
|
||||
<a name="l00077"></a>00077 <span class="comment"> for(produced = 0; produced < NUM_ITEMS; ++produced) {</span>
|
||||
<a name="l00078"></a>00078 <span class="comment"> </span>
|
||||
<a name="l00079"></a>00079 <span class="comment"> PT_SEM_WAIT(pt, &full);</span>
|
||||
<a name="l00080"></a>00080 <span class="comment"> </span>
|
||||
<a name="l00081"></a>00081 <span class="comment"> PT_SEM_WAIT(pt, &mutex);</span>
|
||||
<a name="l00082"></a>00082 <span class="comment"> add_to_buffer(produce_item()); </span>
|
||||
<a name="l00083"></a>00083 <span class="comment"> PT_SEM_SIGNAL(pt, &mutex);</span>
|
||||
<a name="l00084"></a>00084 <span class="comment"> </span>
|
||||
<a name="l00085"></a>00085 <span class="comment"> PT_SEM_SIGNAL(pt, &empty);</span>
|
||||
<a name="l00086"></a>00086 <span class="comment"> }</span>
|
||||
<a name="l00087"></a>00087 <span class="comment"></span>
|
||||
<a name="l00088"></a>00088 <span class="comment"> PT_END(pt);</span>
|
||||
<a name="l00089"></a>00089 <span class="comment">}</span>
|
||||
<a name="l00090"></a>00090 <span class="comment"></span>
|
||||
<a name="l00091"></a>00091 <span class="comment">PT_THREAD(consumer(struct pt *pt))</span>
|
||||
<a name="l00092"></a>00092 <span class="comment">{</span>
|
||||
<a name="l00093"></a>00093 <span class="comment"> static int consumed;</span>
|
||||
<a name="l00094"></a>00094 <span class="comment"> </span>
|
||||
<a name="l00095"></a>00095 <span class="comment"> PT_BEGIN(pt);</span>
|
||||
<a name="l00096"></a>00096 <span class="comment"></span>
|
||||
<a name="l00097"></a>00097 <span class="comment"> for(consumed = 0; consumed < NUM_ITEMS; ++consumed) {</span>
|
||||
<a name="l00098"></a>00098 <span class="comment"> </span>
|
||||
<a name="l00099"></a>00099 <span class="comment"> PT_SEM_WAIT(pt, &empty);</span>
|
||||
<a name="l00100"></a>00100 <span class="comment"> </span>
|
||||
<a name="l00101"></a>00101 <span class="comment"> PT_SEM_WAIT(pt, &mutex); </span>
|
||||
<a name="l00102"></a>00102 <span class="comment"> consume_item(get_from_buffer()); </span>
|
||||
<a name="l00103"></a>00103 <span class="comment"> PT_SEM_SIGNAL(pt, &mutex);</span>
|
||||
<a name="l00104"></a>00104 <span class="comment"> </span>
|
||||
<a name="l00105"></a>00105 <span class="comment"> PT_SEM_SIGNAL(pt, &full);</span>
|
||||
<a name="l00106"></a>00106 <span class="comment"> }</span>
|
||||
<a name="l00107"></a>00107 <span class="comment"></span>
|
||||
<a name="l00108"></a>00108 <span class="comment"> PT_END(pt);</span>
|
||||
<a name="l00109"></a>00109 <span class="comment">}</span>
|
||||
<a name="l00110"></a>00110 <span class="comment"></span>
|
||||
<a name="l00111"></a>00111 <span class="comment">PT_THREAD(driver_thread(struct pt *pt))</span>
|
||||
<a name="l00112"></a>00112 <span class="comment">{</span>
|
||||
<a name="l00113"></a>00113 <span class="comment"> static struct pt pt_producer, pt_consumer;</span>
|
||||
<a name="l00114"></a>00114 <span class="comment"></span>
|
||||
<a name="l00115"></a>00115 <span class="comment"> PT_BEGIN(pt);</span>
|
||||
<a name="l00116"></a>00116 <span class="comment"> </span>
|
||||
<a name="l00117"></a>00117 <span class="comment"> PT_SEM_INIT(&empty, 0);</span>
|
||||
<a name="l00118"></a>00118 <span class="comment"> PT_SEM_INIT(&full, BUFSIZE);</span>
|
||||
<a name="l00119"></a>00119 <span class="comment"> PT_SEM_INIT(&mutex, 1);</span>
|
||||
<a name="l00120"></a>00120 <span class="comment"></span>
|
||||
<a name="l00121"></a>00121 <span class="comment"> PT_INIT(&pt_producer);</span>
|
||||
<a name="l00122"></a>00122 <span class="comment"> PT_INIT(&pt_consumer);</span>
|
||||
<a name="l00123"></a>00123 <span class="comment"></span>
|
||||
<a name="l00124"></a>00124 <span class="comment"> PT_WAIT_THREAD(pt, producer(&pt_producer) &</span>
|
||||
<a name="l00125"></a>00125 <span class="comment"> consumer(&pt_consumer));</span>
|
||||
<a name="l00126"></a>00126 <span class="comment"></span>
|
||||
<a name="l00127"></a>00127 <span class="comment"> PT_END(pt);</span>
|
||||
<a name="l00128"></a>00128 <span class="comment">}</span>
|
||||
<a name="l00129"></a>00129 <span class="comment"> \endcode</span>
|
||||
<a name="l00130"></a>00130 <span class="comment"> *</span>
|
||||
<a name="l00131"></a>00131 <span class="comment"> * The program uses three protothreads: one protothread that</span>
|
||||
<a name="l00132"></a>00132 <span class="comment"> * implements the consumer, one thread that implements the producer,</span>
|
||||
<a name="l00133"></a>00133 <span class="comment"> * and one protothread that drives the two other protothreads. The</span>
|
||||
<a name="l00134"></a>00134 <span class="comment"> * program uses three semaphores: "full", "empty" and "mutex". The</span>
|
||||
<a name="l00135"></a>00135 <span class="comment"> * "mutex" semaphore is used to provide mutual exclusion for the</span>
|
||||
<a name="l00136"></a>00136 <span class="comment"> * buffer, the "empty" semaphore is used to block the consumer is the</span>
|
||||
<a name="l00137"></a>00137 <span class="comment"> * buffer is empty, and the "full" semaphore is used to block the</span>
|
||||
<a name="l00138"></a>00138 <span class="comment"> * producer is the buffer is full.</span>
|
||||
<a name="l00139"></a>00139 <span class="comment"> *</span>
|
||||
<a name="l00140"></a>00140 <span class="comment"> * The "driver_thread" holds two protothread state variables,</span>
|
||||
<a name="l00141"></a>00141 <span class="comment"> * "pt_producer" and "pt_consumer". It is important to note that both</span>
|
||||
<a name="l00142"></a>00142 <span class="comment"> * these variables are declared as <i>static</i>. If the static</span>
|
||||
<a name="l00143"></a>00143 <span class="comment"> * keyword is not used, both variables are stored on the stack. Since</span>
|
||||
<a name="l00144"></a>00144 <span class="comment"> * protothreads do not store the stack, these variables may be</span>
|
||||
<a name="l00145"></a>00145 <span class="comment"> * overwritten during a protothread wait operation. Similarly, both</span>
|
||||
<a name="l00146"></a>00146 <span class="comment"> * the "consumer" and "producer" protothreads declare their local</span>
|
||||
<a name="l00147"></a>00147 <span class="comment"> * variables as static, to avoid them being stored on the stack.</span>
|
||||
<a name="l00148"></a>00148 <span class="comment"> * </span>
|
||||
<a name="l00149"></a>00149 <span class="comment"> *</span>
|
||||
<a name="l00150"></a>00150 <span class="comment"> */</span>
|
||||
<a name="l00151"></a>00151 <span class="comment"></span>
|
||||
<a name="l00152"></a>00152 <span class="comment">/**</span>
|
||||
<a name="l00153"></a>00153 <span class="comment"> * \file</span>
|
||||
<a name="l00154"></a>00154 <span class="comment"> * Couting semaphores implemented on protothreads</span>
|
||||
<a name="l00155"></a>00155 <span class="comment"> * \author</span>
|
||||
<a name="l00156"></a>00156 <span class="comment"> * Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00157"></a>00157 <span class="comment"> *</span>
|
||||
<a name="l00158"></a>00158 <span class="comment"> */</span>
|
||||
<a name="l00159"></a>00159
|
||||
<a name="l00160"></a>00160 <span class="preprocessor">#ifndef __PT_SEM_H__</span>
|
||||
<a name="l00161"></a>00161 <span class="preprocessor"></span><span class="preprocessor">#define __PT_SEM_H__</span>
|
||||
<a name="l00162"></a>00162 <span class="preprocessor"></span>
|
||||
<a name="l00163"></a>00163 <span class="preprocessor">#include "<a class="code" href="a00013.html">pt.h</a>"</span>
|
||||
<a name="l00164"></a>00164
|
||||
<a name="l00165"></a><a class="code" href="a00006.html">00165</a> <span class="keyword">struct </span><a class="code" href="a00006.html">pt_sem</a> {
|
||||
<a name="l00166"></a><a class="code" href="a00006.html#6f341120f42d5fd9f329ff1119594743">00166</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="a00006.html#6f341120f42d5fd9f329ff1119594743">count</a>;
|
||||
<a name="l00167"></a>00167 };
|
||||
<a name="l00168"></a>00168 <span class="comment"></span>
|
||||
<a name="l00169"></a>00169 <span class="comment">/**</span>
|
||||
<a name="l00170"></a>00170 <span class="comment"> * Initialize a semaphore</span>
|
||||
<a name="l00171"></a>00171 <span class="comment"> *</span>
|
||||
<a name="l00172"></a>00172 <span class="comment"> * This macro initializes a semaphore with a value for the</span>
|
||||
<a name="l00173"></a>00173 <span class="comment"> * counter. Internally, the semaphores use an "unsigned int" to</span>
|
||||
<a name="l00174"></a>00174 <span class="comment"> * represent the counter, and therefore the "count" argument should be</span>
|
||||
<a name="l00175"></a>00175 <span class="comment"> * within range of an unsigned int.</span>
|
||||
<a name="l00176"></a>00176 <span class="comment"> *</span>
|
||||
<a name="l00177"></a>00177 <span class="comment"> * \param s (struct pt_sem *) A pointer to the pt_sem struct</span>
|
||||
<a name="l00178"></a>00178 <span class="comment"> * representing the semaphore</span>
|
||||
<a name="l00179"></a>00179 <span class="comment"> *</span>
|
||||
<a name="l00180"></a>00180 <span class="comment"> * \param c (unsigned int) The initial count of the semaphore.</span>
|
||||
<a name="l00181"></a>00181 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00182"></a>00182 <span class="comment"> */</span>
|
||||
<a name="l00183"></a><a class="code" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">00183</a> <span class="preprocessor">#define PT_SEM_INIT(s, c) (s)->count = c</span>
|
||||
<a name="l00184"></a>00184 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00185"></a>00185 <span class="comment">/**</span>
|
||||
<a name="l00186"></a>00186 <span class="comment"> * Wait for a semaphore</span>
|
||||
<a name="l00187"></a>00187 <span class="comment"> *</span>
|
||||
<a name="l00188"></a>00188 <span class="comment"> * This macro carries out the "wait" operation on the semaphore. The</span>
|
||||
<a name="l00189"></a>00189 <span class="comment"> * wait operation causes the protothread to block while the counter is</span>
|
||||
<a name="l00190"></a>00190 <span class="comment"> * zero. When the counter reaches a value larger than zero, the</span>
|
||||
<a name="l00191"></a>00191 <span class="comment"> * protothread will continue.</span>
|
||||
<a name="l00192"></a>00192 <span class="comment"> *</span>
|
||||
<a name="l00193"></a>00193 <span class="comment"> * \param pt (struct pt *) A pointer to the protothread (struct pt) in</span>
|
||||
<a name="l00194"></a>00194 <span class="comment"> * which the operation is executed.</span>
|
||||
<a name="l00195"></a>00195 <span class="comment"> *</span>
|
||||
<a name="l00196"></a>00196 <span class="comment"> * \param s (struct pt_sem *) A pointer to the pt_sem struct</span>
|
||||
<a name="l00197"></a>00197 <span class="comment"> * representing the semaphore</span>
|
||||
<a name="l00198"></a>00198 <span class="comment"> *</span>
|
||||
<a name="l00199"></a>00199 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00200"></a>00200 <span class="comment"> */</span>
|
||||
<a name="l00201"></a><a class="code" href="a00016.html#g386ff87a52a840512906f2940e229e2e">00201</a> <span class="preprocessor">#define PT_SEM_WAIT(pt, s) \</span>
|
||||
<a name="l00202"></a>00202 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00203"></a>00203 <span class="preprocessor"> PT_WAIT_UNTIL(pt, (s)->count > 0); \</span>
|
||||
<a name="l00204"></a>00204 <span class="preprocessor"> --(s)->count; \</span>
|
||||
<a name="l00205"></a>00205 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00206"></a>00206 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00207"></a>00207 <span class="comment">/**</span>
|
||||
<a name="l00208"></a>00208 <span class="comment"> * Signal a semaphore</span>
|
||||
<a name="l00209"></a>00209 <span class="comment"> *</span>
|
||||
<a name="l00210"></a>00210 <span class="comment"> * This macro carries out the "signal" operation on the semaphore. The</span>
|
||||
<a name="l00211"></a>00211 <span class="comment"> * signal operation increments the counter inside the semaphore, which</span>
|
||||
<a name="l00212"></a>00212 <span class="comment"> * eventually will cause waiting protothreads to continue executing.</span>
|
||||
<a name="l00213"></a>00213 <span class="comment"> *</span>
|
||||
<a name="l00214"></a>00214 <span class="comment"> * \param pt (struct pt *) A pointer to the protothread (struct pt) in</span>
|
||||
<a name="l00215"></a>00215 <span class="comment"> * which the operation is executed.</span>
|
||||
<a name="l00216"></a>00216 <span class="comment"> *</span>
|
||||
<a name="l00217"></a>00217 <span class="comment"> * \param s (struct pt_sem *) A pointer to the pt_sem struct</span>
|
||||
<a name="l00218"></a>00218 <span class="comment"> * representing the semaphore</span>
|
||||
<a name="l00219"></a>00219 <span class="comment"> *</span>
|
||||
<a name="l00220"></a>00220 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00221"></a>00221 <span class="comment"> */</span>
|
||||
<a name="l00222"></a><a class="code" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">00222</a> <span class="preprocessor">#define PT_SEM_SIGNAL(pt, s) ++(s)->count</span>
|
||||
<a name="l00223"></a>00223 <span class="preprocessor"></span>
|
||||
<a name="l00224"></a>00224 <span class="preprocessor">#endif </span><span class="comment">/* __PT_SEM_H__ */</span>
|
||||
<a name="l00225"></a>00225 <span class="comment"></span>
|
||||
<a name="l00226"></a>00226 <span class="comment">/** @} */</span><span class="comment"></span>
|
||||
<a name="l00227"></a>00227 <span class="comment">/** @} */</span>
|
||||
<a name="l00228"></a>00228
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,347 @@
|
|||
<!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.4: pt.h 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.4.6 -->
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>pt.h</h1><a href="a00013.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2004-2005, Swedish Institute of Computer Science.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved.</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> *</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * are met:</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * may be used to endorse or promote products derived from this software</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * without specific prior written permission.</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> *</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
|
||||
<a name="l00022"></a>00022 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
|
||||
<a name="l00023"></a>00023 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
|
||||
<a name="l00024"></a>00024 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
|
||||
<a name="l00025"></a>00025 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
|
||||
<a name="l00026"></a>00026 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
|
||||
<a name="l00027"></a>00027 <span class="comment"> * SUCH DAMAGE.</span>
|
||||
<a name="l00028"></a>00028 <span class="comment"> *</span>
|
||||
<a name="l00029"></a>00029 <span class="comment"> * This file is part of the Contiki operating system.</span>
|
||||
<a name="l00030"></a>00030 <span class="comment"> *</span>
|
||||
<a name="l00031"></a>00031 <span class="comment"> * Author: Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00032"></a>00032 <span class="comment"> *</span>
|
||||
<a name="l00033"></a>00033 <span class="comment"> * $Id: pt.h,v 1.7 2006/10/02 07:52:56 adam Exp $</span>
|
||||
<a name="l00034"></a>00034 <span class="comment"> */</span>
|
||||
<a name="l00035"></a>00035 <span class="comment"></span>
|
||||
<a name="l00036"></a>00036 <span class="comment">/**</span>
|
||||
<a name="l00037"></a>00037 <span class="comment"> * \addtogroup pt</span>
|
||||
<a name="l00038"></a>00038 <span class="comment"> * @{</span>
|
||||
<a name="l00039"></a>00039 <span class="comment"> */</span>
|
||||
<a name="l00040"></a>00040 <span class="comment"></span>
|
||||
<a name="l00041"></a>00041 <span class="comment">/**</span>
|
||||
<a name="l00042"></a>00042 <span class="comment"> * \file</span>
|
||||
<a name="l00043"></a>00043 <span class="comment"> * Protothreads implementation.</span>
|
||||
<a name="l00044"></a>00044 <span class="comment"> * \author</span>
|
||||
<a name="l00045"></a>00045 <span class="comment"> * Adam Dunkels <adam@sics.se></span>
|
||||
<a name="l00046"></a>00046 <span class="comment"> *</span>
|
||||
<a name="l00047"></a>00047 <span class="comment"> */</span>
|
||||
<a name="l00048"></a>00048
|
||||
<a name="l00049"></a>00049 <span class="preprocessor">#ifndef __PT_H__</span>
|
||||
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define __PT_H__</span>
|
||||
<a name="l00051"></a>00051 <span class="preprocessor"></span>
|
||||
<a name="l00052"></a>00052 <span class="preprocessor">#include "<a class="code" href="a00011.html">lc.h</a>"</span>
|
||||
<a name="l00053"></a>00053
|
||||
<a name="l00054"></a><a class="code" href="a00005.html">00054</a> <span class="keyword">struct </span><a class="code" href="a00005.html">pt</a> {
|
||||
<a name="l00055"></a><a class="code" href="a00005.html#c3fa0fa86689e3e7c039a16c16861dbe">00055</a> <a class="code" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc_t</a> <a class="code" href="a00005.html#c3fa0fa86689e3e7c039a16c16861dbe">lc</a>;
|
||||
<a name="l00056"></a>00056 };
|
||||
<a name="l00057"></a>00057
|
||||
<a name="l00058"></a><a class="code" href="a00014.html#g7b5319b5b65761a845fcd1500fde4cdc">00058</a> <span class="preprocessor">#define PT_WAITING 0</span>
|
||||
<a name="l00059"></a><a class="code" href="a00014.html#ge469332907e0617d72d5e2dd4297119d">00059</a> <span class="preprocessor"></span><span class="preprocessor">#define PT_YIELDED 1</span>
|
||||
<a name="l00060"></a><a class="code" href="a00014.html#gcfae9053e5c107a1aed6b228c917d2ea">00060</a> <span class="preprocessor"></span><span class="preprocessor">#define PT_EXITED 2</span>
|
||||
<a name="l00061"></a><a class="code" href="a00014.html#g9ff1e8936a8a26bff54c05f8a989b93b">00061</a> <span class="preprocessor"></span><span class="preprocessor">#define PT_ENDED 3</span>
|
||||
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00063"></a>00063 <span class="comment">/**</span>
|
||||
<a name="l00064"></a>00064 <span class="comment"> * \name Initialization</span>
|
||||
<a name="l00065"></a>00065 <span class="comment"> * @{</span>
|
||||
<a name="l00066"></a>00066 <span class="comment"> */</span>
|
||||
<a name="l00067"></a>00067 <span class="comment"></span>
|
||||
<a name="l00068"></a>00068 <span class="comment">/**</span>
|
||||
<a name="l00069"></a>00069 <span class="comment"> * Initialize a protothread.</span>
|
||||
<a name="l00070"></a>00070 <span class="comment"> *</span>
|
||||
<a name="l00071"></a>00071 <span class="comment"> * Initializes a protothread. Initialization must be done prior to</span>
|
||||
<a name="l00072"></a>00072 <span class="comment"> * starting to execute the protothread.</span>
|
||||
<a name="l00073"></a>00073 <span class="comment"> *</span>
|
||||
<a name="l00074"></a>00074 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00075"></a>00075 <span class="comment"> *</span>
|
||||
<a name="l00076"></a>00076 <span class="comment"> * \sa PT_SPAWN()</span>
|
||||
<a name="l00077"></a>00077 <span class="comment"> *</span>
|
||||
<a name="l00078"></a>00078 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00079"></a>00079 <span class="comment"> */</span>
|
||||
<a name="l00080"></a><a class="code" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">00080</a> <span class="preprocessor">#define PT_INIT(pt) LC_INIT((pt)->lc)</span>
|
||||
<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00082"></a>00082 <span class="comment">/** @} */</span>
|
||||
<a name="l00083"></a>00083 <span class="comment"></span>
|
||||
<a name="l00084"></a>00084 <span class="comment">/**</span>
|
||||
<a name="l00085"></a>00085 <span class="comment"> * \name Declaration and definition</span>
|
||||
<a name="l00086"></a>00086 <span class="comment"> * @{</span>
|
||||
<a name="l00087"></a>00087 <span class="comment"> */</span>
|
||||
<a name="l00088"></a>00088 <span class="comment"></span>
|
||||
<a name="l00089"></a>00089 <span class="comment">/**</span>
|
||||
<a name="l00090"></a>00090 <span class="comment"> * Declaration of a protothread.</span>
|
||||
<a name="l00091"></a>00091 <span class="comment"> *</span>
|
||||
<a name="l00092"></a>00092 <span class="comment"> * This macro is used to declare a protothread. All protothreads must</span>
|
||||
<a name="l00093"></a>00093 <span class="comment"> * be declared with this macro.</span>
|
||||
<a name="l00094"></a>00094 <span class="comment"> *</span>
|
||||
<a name="l00095"></a>00095 <span class="comment"> * \param name_args The name and arguments of the C function</span>
|
||||
<a name="l00096"></a>00096 <span class="comment"> * implementing the protothread.</span>
|
||||
<a name="l00097"></a>00097 <span class="comment"> *</span>
|
||||
<a name="l00098"></a>00098 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00099"></a>00099 <span class="comment"> */</span>
|
||||
<a name="l00100"></a><a class="code" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">00100</a> <span class="preprocessor">#define PT_THREAD(name_args) char name_args</span>
|
||||
<a name="l00101"></a>00101 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00102"></a>00102 <span class="comment">/**</span>
|
||||
<a name="l00103"></a>00103 <span class="comment"> * Declare the start of a protothread inside the C function</span>
|
||||
<a name="l00104"></a>00104 <span class="comment"> * implementing the protothread.</span>
|
||||
<a name="l00105"></a>00105 <span class="comment"> *</span>
|
||||
<a name="l00106"></a>00106 <span class="comment"> * This macro is used to declare the starting point of a</span>
|
||||
<a name="l00107"></a>00107 <span class="comment"> * protothread. It should be placed at the start of the function in</span>
|
||||
<a name="l00108"></a>00108 <span class="comment"> * which the protothread runs. All C statements above the PT_BEGIN()</span>
|
||||
<a name="l00109"></a>00109 <span class="comment"> * invokation will be executed each time the protothread is scheduled.</span>
|
||||
<a name="l00110"></a>00110 <span class="comment"> *</span>
|
||||
<a name="l00111"></a>00111 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00112"></a>00112 <span class="comment"> *</span>
|
||||
<a name="l00113"></a>00113 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00114"></a>00114 <span class="comment"> */</span>
|
||||
<a name="l00115"></a><a class="code" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">00115</a> <span class="preprocessor">#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)</span>
|
||||
<a name="l00116"></a>00116 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00117"></a>00117 <span class="comment">/**</span>
|
||||
<a name="l00118"></a>00118 <span class="comment"> * Declare the end of a protothread.</span>
|
||||
<a name="l00119"></a>00119 <span class="comment"> *</span>
|
||||
<a name="l00120"></a>00120 <span class="comment"> * This macro is used for declaring that a protothread ends. It must</span>
|
||||
<a name="l00121"></a>00121 <span class="comment"> * always be used together with a matching PT_BEGIN() macro.</span>
|
||||
<a name="l00122"></a>00122 <span class="comment"> *</span>
|
||||
<a name="l00123"></a>00123 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00124"></a>00124 <span class="comment"> *</span>
|
||||
<a name="l00125"></a>00125 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00126"></a>00126 <span class="comment"> */</span>
|
||||
<a name="l00127"></a><a class="code" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">00127</a> <span class="preprocessor">#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \</span>
|
||||
<a name="l00128"></a>00128 <span class="preprocessor"> PT_INIT(pt); return PT_ENDED; }</span>
|
||||
<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00130"></a>00130 <span class="comment">/** @} */</span>
|
||||
<a name="l00131"></a>00131 <span class="comment"></span>
|
||||
<a name="l00132"></a>00132 <span class="comment">/**</span>
|
||||
<a name="l00133"></a>00133 <span class="comment"> * \name Blocked wait</span>
|
||||
<a name="l00134"></a>00134 <span class="comment"> * @{</span>
|
||||
<a name="l00135"></a>00135 <span class="comment"> */</span>
|
||||
<a name="l00136"></a>00136 <span class="comment"></span>
|
||||
<a name="l00137"></a>00137 <span class="comment">/**</span>
|
||||
<a name="l00138"></a>00138 <span class="comment"> * Block and wait until condition is true.</span>
|
||||
<a name="l00139"></a>00139 <span class="comment"> *</span>
|
||||
<a name="l00140"></a>00140 <span class="comment"> * This macro blocks the protothread until the specified condition is</span>
|
||||
<a name="l00141"></a>00141 <span class="comment"> * true.</span>
|
||||
<a name="l00142"></a>00142 <span class="comment"> *</span>
|
||||
<a name="l00143"></a>00143 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00144"></a>00144 <span class="comment"> * \param condition The condition.</span>
|
||||
<a name="l00145"></a>00145 <span class="comment"> *</span>
|
||||
<a name="l00146"></a>00146 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00147"></a>00147 <span class="comment"> */</span>
|
||||
<a name="l00148"></a><a class="code" href="a00014.html#g99e43010ec61327164466aa2d902de45">00148</a> <span class="preprocessor">#define PT_WAIT_UNTIL(pt, condition) \</span>
|
||||
<a name="l00149"></a>00149 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00150"></a>00150 <span class="preprocessor"> LC_SET((pt)->lc); \</span>
|
||||
<a name="l00151"></a>00151 <span class="preprocessor"> if(!(condition)) { \</span>
|
||||
<a name="l00152"></a>00152 <span class="preprocessor"> return PT_WAITING; \</span>
|
||||
<a name="l00153"></a>00153 <span class="preprocessor"> } \</span>
|
||||
<a name="l00154"></a>00154 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00155"></a>00155 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00156"></a>00156 <span class="comment">/**</span>
|
||||
<a name="l00157"></a>00157 <span class="comment"> * Block and wait while condition is true.</span>
|
||||
<a name="l00158"></a>00158 <span class="comment"> *</span>
|
||||
<a name="l00159"></a>00159 <span class="comment"> * This function blocks and waits while condition is true. See</span>
|
||||
<a name="l00160"></a>00160 <span class="comment"> * PT_WAIT_UNTIL().</span>
|
||||
<a name="l00161"></a>00161 <span class="comment"> *</span>
|
||||
<a name="l00162"></a>00162 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00163"></a>00163 <span class="comment"> * \param cond The condition.</span>
|
||||
<a name="l00164"></a>00164 <span class="comment"> *</span>
|
||||
<a name="l00165"></a>00165 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00166"></a>00166 <span class="comment"> */</span>
|
||||
<a name="l00167"></a><a class="code" href="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d">00167</a> <span class="preprocessor">#define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))</span>
|
||||
<a name="l00168"></a>00168 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00169"></a>00169 <span class="comment">/** @} */</span>
|
||||
<a name="l00170"></a>00170 <span class="comment"></span>
|
||||
<a name="l00171"></a>00171 <span class="comment">/**</span>
|
||||
<a name="l00172"></a>00172 <span class="comment"> * \name Hierarchical protothreads</span>
|
||||
<a name="l00173"></a>00173 <span class="comment"> * @{</span>
|
||||
<a name="l00174"></a>00174 <span class="comment"> */</span>
|
||||
<a name="l00175"></a>00175 <span class="comment"></span>
|
||||
<a name="l00176"></a>00176 <span class="comment">/**</span>
|
||||
<a name="l00177"></a>00177 <span class="comment"> * Block and wait until a child protothread completes.</span>
|
||||
<a name="l00178"></a>00178 <span class="comment"> *</span>
|
||||
<a name="l00179"></a>00179 <span class="comment"> * This macro schedules a child protothread. The current protothread</span>
|
||||
<a name="l00180"></a>00180 <span class="comment"> * will block until the child protothread completes.</span>
|
||||
<a name="l00181"></a>00181 <span class="comment"> *</span>
|
||||
<a name="l00182"></a>00182 <span class="comment"> * \note The child protothread must be manually initialized with the</span>
|
||||
<a name="l00183"></a>00183 <span class="comment"> * PT_INIT() function before this function is used.</span>
|
||||
<a name="l00184"></a>00184 <span class="comment"> *</span>
|
||||
<a name="l00185"></a>00185 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00186"></a>00186 <span class="comment"> * \param thread The child protothread with arguments</span>
|
||||
<a name="l00187"></a>00187 <span class="comment"> *</span>
|
||||
<a name="l00188"></a>00188 <span class="comment"> * \sa PT_SPAWN()</span>
|
||||
<a name="l00189"></a>00189 <span class="comment"> *</span>
|
||||
<a name="l00190"></a>00190 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00191"></a>00191 <span class="comment"> */</span>
|
||||
<a name="l00192"></a><a class="code" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">00192</a> <span class="preprocessor">#define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))</span>
|
||||
<a name="l00193"></a>00193 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00194"></a>00194 <span class="comment">/**</span>
|
||||
<a name="l00195"></a>00195 <span class="comment"> * Spawn a child protothread and wait until it exits.</span>
|
||||
<a name="l00196"></a>00196 <span class="comment"> *</span>
|
||||
<a name="l00197"></a>00197 <span class="comment"> * This macro spawns a child protothread and waits until it exits. The</span>
|
||||
<a name="l00198"></a>00198 <span class="comment"> * macro can only be used within a protothread.</span>
|
||||
<a name="l00199"></a>00199 <span class="comment"> *</span>
|
||||
<a name="l00200"></a>00200 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00201"></a>00201 <span class="comment"> * \param child A pointer to the child protothread's control structure.</span>
|
||||
<a name="l00202"></a>00202 <span class="comment"> * \param thread The child protothread with arguments</span>
|
||||
<a name="l00203"></a>00203 <span class="comment"> *</span>
|
||||
<a name="l00204"></a>00204 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00205"></a>00205 <span class="comment"> */</span>
|
||||
<a name="l00206"></a><a class="code" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">00206</a> <span class="preprocessor">#define PT_SPAWN(pt, child, thread) \</span>
|
||||
<a name="l00207"></a>00207 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00208"></a>00208 <span class="preprocessor"> PT_INIT((child)); \</span>
|
||||
<a name="l00209"></a>00209 <span class="preprocessor"> PT_WAIT_THREAD((pt), (thread)); \</span>
|
||||
<a name="l00210"></a>00210 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00211"></a>00211 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00212"></a>00212 <span class="comment">/** @} */</span>
|
||||
<a name="l00213"></a>00213 <span class="comment"></span>
|
||||
<a name="l00214"></a>00214 <span class="comment">/**</span>
|
||||
<a name="l00215"></a>00215 <span class="comment"> * \name Exiting and restarting</span>
|
||||
<a name="l00216"></a>00216 <span class="comment"> * @{</span>
|
||||
<a name="l00217"></a>00217 <span class="comment"> */</span>
|
||||
<a name="l00218"></a>00218 <span class="comment"></span>
|
||||
<a name="l00219"></a>00219 <span class="comment">/**</span>
|
||||
<a name="l00220"></a>00220 <span class="comment"> * Restart the protothread.</span>
|
||||
<a name="l00221"></a>00221 <span class="comment"> *</span>
|
||||
<a name="l00222"></a>00222 <span class="comment"> * This macro will block and cause the running protothread to restart</span>
|
||||
<a name="l00223"></a>00223 <span class="comment"> * its execution at the place of the PT_BEGIN() call.</span>
|
||||
<a name="l00224"></a>00224 <span class="comment"> *</span>
|
||||
<a name="l00225"></a>00225 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00226"></a>00226 <span class="comment"> *</span>
|
||||
<a name="l00227"></a>00227 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00228"></a>00228 <span class="comment"> */</span>
|
||||
<a name="l00229"></a><a class="code" href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">00229</a> <span class="preprocessor">#define PT_RESTART(pt) \</span>
|
||||
<a name="l00230"></a>00230 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00231"></a>00231 <span class="preprocessor"> PT_INIT(pt); \</span>
|
||||
<a name="l00232"></a>00232 <span class="preprocessor"> return PT_WAITING; \</span>
|
||||
<a name="l00233"></a>00233 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00234"></a>00234 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00235"></a>00235 <span class="comment">/**</span>
|
||||
<a name="l00236"></a>00236 <span class="comment"> * Exit the protothread.</span>
|
||||
<a name="l00237"></a>00237 <span class="comment"> *</span>
|
||||
<a name="l00238"></a>00238 <span class="comment"> * This macro causes the protothread to exit. If the protothread was</span>
|
||||
<a name="l00239"></a>00239 <span class="comment"> * spawned by another protothread, the parent protothread will become</span>
|
||||
<a name="l00240"></a>00240 <span class="comment"> * unblocked and can continue to run.</span>
|
||||
<a name="l00241"></a>00241 <span class="comment"> *</span>
|
||||
<a name="l00242"></a>00242 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00243"></a>00243 <span class="comment"> *</span>
|
||||
<a name="l00244"></a>00244 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00245"></a>00245 <span class="comment"> */</span>
|
||||
<a name="l00246"></a><a class="code" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">00246</a> <span class="preprocessor">#define PT_EXIT(pt) \</span>
|
||||
<a name="l00247"></a>00247 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00248"></a>00248 <span class="preprocessor"> PT_INIT(pt); \</span>
|
||||
<a name="l00249"></a>00249 <span class="preprocessor"> return PT_EXITED; \</span>
|
||||
<a name="l00250"></a>00250 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00251"></a>00251 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00252"></a>00252 <span class="comment">/** @} */</span>
|
||||
<a name="l00253"></a>00253 <span class="comment"></span>
|
||||
<a name="l00254"></a>00254 <span class="comment">/**</span>
|
||||
<a name="l00255"></a>00255 <span class="comment"> * \name Calling a protothread</span>
|
||||
<a name="l00256"></a>00256 <span class="comment"> * @{</span>
|
||||
<a name="l00257"></a>00257 <span class="comment"> */</span>
|
||||
<a name="l00258"></a>00258 <span class="comment"></span>
|
||||
<a name="l00259"></a>00259 <span class="comment">/**</span>
|
||||
<a name="l00260"></a>00260 <span class="comment"> * Schedule a protothread.</span>
|
||||
<a name="l00261"></a>00261 <span class="comment"> *</span>
|
||||
<a name="l00262"></a>00262 <span class="comment"> * This function shedules a protothread. The return value of the</span>
|
||||
<a name="l00263"></a>00263 <span class="comment"> * function is non-zero if the protothread is running or zero if the</span>
|
||||
<a name="l00264"></a>00264 <span class="comment"> * protothread has exited.</span>
|
||||
<a name="l00265"></a>00265 <span class="comment"> *</span>
|
||||
<a name="l00266"></a>00266 <span class="comment"> * \param f The call to the C function implementing the protothread to</span>
|
||||
<a name="l00267"></a>00267 <span class="comment"> * be scheduled</span>
|
||||
<a name="l00268"></a>00268 <span class="comment"> *</span>
|
||||
<a name="l00269"></a>00269 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00270"></a>00270 <span class="comment"> */</span>
|
||||
<a name="l00271"></a><a class="code" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">00271</a> <span class="preprocessor">#define PT_SCHEDULE(f) ((f) < PT_EXITED)</span>
|
||||
<a name="l00272"></a>00272 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00273"></a>00273 <span class="comment">/** @} */</span>
|
||||
<a name="l00274"></a>00274 <span class="comment"></span>
|
||||
<a name="l00275"></a>00275 <span class="comment">/**</span>
|
||||
<a name="l00276"></a>00276 <span class="comment"> * \name Yielding from a protothread</span>
|
||||
<a name="l00277"></a>00277 <span class="comment"> * @{</span>
|
||||
<a name="l00278"></a>00278 <span class="comment"> */</span>
|
||||
<a name="l00279"></a>00279 <span class="comment"></span>
|
||||
<a name="l00280"></a>00280 <span class="comment">/**</span>
|
||||
<a name="l00281"></a>00281 <span class="comment"> * Yield from the current protothread.</span>
|
||||
<a name="l00282"></a>00282 <span class="comment"> *</span>
|
||||
<a name="l00283"></a>00283 <span class="comment"> * This function will yield the protothread, thereby allowing other</span>
|
||||
<a name="l00284"></a>00284 <span class="comment"> * processing to take place in the system.</span>
|
||||
<a name="l00285"></a>00285 <span class="comment"> *</span>
|
||||
<a name="l00286"></a>00286 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00287"></a>00287 <span class="comment"> *</span>
|
||||
<a name="l00288"></a>00288 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00289"></a>00289 <span class="comment"> */</span>
|
||||
<a name="l00290"></a><a class="code" href="a00014.html#g155cba6121323726d02c00284428fed6">00290</a> <span class="preprocessor">#define PT_YIELD(pt) \</span>
|
||||
<a name="l00291"></a>00291 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00292"></a>00292 <span class="preprocessor"> PT_YIELD_FLAG = 0; \</span>
|
||||
<a name="l00293"></a>00293 <span class="preprocessor"> LC_SET((pt)->lc); \</span>
|
||||
<a name="l00294"></a>00294 <span class="preprocessor"> if(PT_YIELD_FLAG == 0) { \</span>
|
||||
<a name="l00295"></a>00295 <span class="preprocessor"> return PT_YIELDED; \</span>
|
||||
<a name="l00296"></a>00296 <span class="preprocessor"> } \</span>
|
||||
<a name="l00297"></a>00297 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00298"></a>00298 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00299"></a>00299 <span class="comment">/**</span>
|
||||
<a name="l00300"></a>00300 <span class="comment"> * \brief Yield from the protothread until a condition occurs.</span>
|
||||
<a name="l00301"></a>00301 <span class="comment"> * \param pt A pointer to the protothread control structure.</span>
|
||||
<a name="l00302"></a>00302 <span class="comment"> * \param cond The condition.</span>
|
||||
<a name="l00303"></a>00303 <span class="comment"> *</span>
|
||||
<a name="l00304"></a>00304 <span class="comment"> * This function will yield the protothread, until the</span>
|
||||
<a name="l00305"></a>00305 <span class="comment"> * specified condition evaluates to true.</span>
|
||||
<a name="l00306"></a>00306 <span class="comment"> *</span>
|
||||
<a name="l00307"></a>00307 <span class="comment"> *</span>
|
||||
<a name="l00308"></a>00308 <span class="comment"> * \hideinitializer</span>
|
||||
<a name="l00309"></a>00309 <span class="comment"> */</span>
|
||||
<a name="l00310"></a><a class="code" href="a00014.html#ge3c821e3a388615528efda9d23c7d115">00310</a> <span class="preprocessor">#define PT_YIELD_UNTIL(pt, cond) \</span>
|
||||
<a name="l00311"></a>00311 <span class="preprocessor"> do { \</span>
|
||||
<a name="l00312"></a>00312 <span class="preprocessor"> PT_YIELD_FLAG = 0; \</span>
|
||||
<a name="l00313"></a>00313 <span class="preprocessor"> LC_SET((pt)->lc); \</span>
|
||||
<a name="l00314"></a>00314 <span class="preprocessor"> if((PT_YIELD_FLAG == 0) || !(cond)) { \</span>
|
||||
<a name="l00315"></a>00315 <span class="preprocessor"> return PT_YIELDED; \</span>
|
||||
<a name="l00316"></a>00316 <span class="preprocessor"> } \</span>
|
||||
<a name="l00317"></a>00317 <span class="preprocessor"> } while(0)</span>
|
||||
<a name="l00318"></a>00318 <span class="preprocessor"></span><span class="comment"></span>
|
||||
<a name="l00319"></a>00319 <span class="comment">/** @} */</span>
|
||||
<a name="l00320"></a>00320
|
||||
<a name="l00321"></a>00321 <span class="preprocessor">#endif </span><span class="comment">/* __PT_H__ */</span>
|
||||
<a name="l00322"></a>00322 <span class="comment"></span>
|
||||
<a name="l00323"></a>00323 <span class="comment">/** @} */</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,29 @@
|
|||
<!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.4: Data Structures</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<h1>The Protothreads Library 1.4 Data Structures</h1>Here are the data structures with brief descriptions:<table>
|
||||
<tr><td class="indexkey"><a class="el" href="a00005.html">pt</a></td><td class="indexvalue"></td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="a00006.html">pt_sem</a></td><td class="indexvalue"></td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,310 @@
|
|||
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
|
||||
font-family: Geneva, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
BODY,TD {
|
||||
font-size: 90%;
|
||||
}
|
||||
H1 {
|
||||
text-align: center;
|
||||
font-size: 160%;
|
||||
}
|
||||
H2 {
|
||||
font-size: 120%;
|
||||
}
|
||||
H3 {
|
||||
font-size: 100%;
|
||||
}
|
||||
CAPTION { font-weight: bold }
|
||||
DIV.qindex {
|
||||
width: 100%;
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #84b0c7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
padding: 2px;
|
||||
line-height: 140%;
|
||||
}
|
||||
DIV.nav {
|
||||
width: 100%;
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #84b0c7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
padding: 2px;
|
||||
line-height: 140%;
|
||||
}
|
||||
DIV.navtab {
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #84b0c7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
margin-right: 15px;
|
||||
padding: 2px;
|
||||
}
|
||||
TD.navtab {
|
||||
font-size: 70%;
|
||||
}
|
||||
A.qindex {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
color: #1A419D;
|
||||
}
|
||||
A.qindex:visited {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
color: #1A419D
|
||||
}
|
||||
A.qindex:hover {
|
||||
text-decoration: none;
|
||||
background-color: #ddddff;
|
||||
}
|
||||
A.qindexHL {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
background-color: #6666cc;
|
||||
color: #ffffff;
|
||||
border: 1px double #9295C2;
|
||||
}
|
||||
A.qindexHL:hover {
|
||||
text-decoration: none;
|
||||
background-color: #6666cc;
|
||||
color: #ffffff;
|
||||
}
|
||||
A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff }
|
||||
A.el { text-decoration: none; font-weight: bold }
|
||||
A.elRef { font-weight: bold }
|
||||
A.code:link { text-decoration: none; font-weight: normal; color: #0000FF}
|
||||
A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF}
|
||||
A.codeRef:link { font-weight: normal; color: #0000FF}
|
||||
A.codeRef:visited { font-weight: normal; color: #0000FF}
|
||||
A:hover { text-decoration: none; background-color: #f2f2ff }
|
||||
DL.el { margin-left: -1cm }
|
||||
.fragment {
|
||||
font-family: Fixed, monospace;
|
||||
font-size: 95%;
|
||||
}
|
||||
PRE.fragment {
|
||||
border: 1px solid #CCCCCC;
|
||||
background-color: #f5f5f5;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
margin-left: 2px;
|
||||
margin-right: 8px;
|
||||
padding-left: 6px;
|
||||
padding-right: 6px;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
|
||||
TD.md { background-color: #F4F4FB; font-weight: bold; }
|
||||
TD.mdPrefix {
|
||||
background-color: #F4F4FB;
|
||||
color: #606060;
|
||||
font-size: 80%;
|
||||
}
|
||||
TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; }
|
||||
TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; }
|
||||
DIV.groupHeader {
|
||||
margin-left: 16px;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 6px;
|
||||
font-weight: bold;
|
||||
}
|
||||
DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% }
|
||||
BODY {
|
||||
background: white;
|
||||
color: black;
|
||||
margin-right: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
TD.indexkey {
|
||||
background-color: #e8eef2;
|
||||
font-weight: bold;
|
||||
padding-right : 10px;
|
||||
padding-top : 2px;
|
||||
padding-left : 10px;
|
||||
padding-bottom : 2px;
|
||||
margin-left : 0px;
|
||||
margin-right : 0px;
|
||||
margin-top : 2px;
|
||||
margin-bottom : 2px;
|
||||
border: 1px solid #CCCCCC;
|
||||
}
|
||||
TD.indexvalue {
|
||||
background-color: #e8eef2;
|
||||
font-style: italic;
|
||||
padding-right : 10px;
|
||||
padding-top : 2px;
|
||||
padding-left : 10px;
|
||||
padding-bottom : 2px;
|
||||
margin-left : 0px;
|
||||
margin-right : 0px;
|
||||
margin-top : 2px;
|
||||
margin-bottom : 2px;
|
||||
border: 1px solid #CCCCCC;
|
||||
}
|
||||
TR.memlist {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
P.formulaDsp { text-align: center; }
|
||||
IMG.formulaDsp { }
|
||||
IMG.formulaInl { vertical-align: middle; }
|
||||
SPAN.keyword { color: #008000 }
|
||||
SPAN.keywordtype { color: #604020 }
|
||||
SPAN.keywordflow { color: #e08000 }
|
||||
SPAN.comment { color: #800000 }
|
||||
SPAN.preprocessor { color: #806020 }
|
||||
SPAN.stringliteral { color: #002080 }
|
||||
SPAN.charliteral { color: #008080 }
|
||||
.mdTable {
|
||||
border: 1px solid #868686;
|
||||
background-color: #F4F4FB;
|
||||
}
|
||||
.mdRow {
|
||||
padding: 8px 10px;
|
||||
}
|
||||
.mdescLeft {
|
||||
padding: 0px 8px 4px 8px;
|
||||
font-size: 80%;
|
||||
font-style: italic;
|
||||
background-color: #FAFAFA;
|
||||
border-top: 1px none #E0E0E0;
|
||||
border-right: 1px none #E0E0E0;
|
||||
border-bottom: 1px none #E0E0E0;
|
||||
border-left: 1px none #E0E0E0;
|
||||
margin: 0px;
|
||||
}
|
||||
.mdescRight {
|
||||
padding: 0px 8px 4px 8px;
|
||||
font-size: 80%;
|
||||
font-style: italic;
|
||||
background-color: #FAFAFA;
|
||||
border-top: 1px none #E0E0E0;
|
||||
border-right: 1px none #E0E0E0;
|
||||
border-bottom: 1px none #E0E0E0;
|
||||
border-left: 1px none #E0E0E0;
|
||||
margin: 0px;
|
||||
}
|
||||
.memItemLeft {
|
||||
padding: 1px 0px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-top-style: solid;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-size: 80%;
|
||||
}
|
||||
.memItemRight {
|
||||
padding: 1px 8px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-top-style: solid;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-size: 80%;
|
||||
}
|
||||
.memTemplItemLeft {
|
||||
padding: 1px 0px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-top-style: none;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-size: 80%;
|
||||
}
|
||||
.memTemplItemRight {
|
||||
padding: 1px 8px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-top-style: none;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-size: 80%;
|
||||
}
|
||||
.memTemplParams {
|
||||
padding: 1px 0px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-top-style: solid;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
color: #606060;
|
||||
background-color: #FAFAFA;
|
||||
font-size: 80%;
|
||||
}
|
||||
.search { color: #003399;
|
||||
font-weight: bold;
|
||||
}
|
||||
FORM.search {
|
||||
margin-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
}
|
||||
INPUT.search { font-size: 75%;
|
||||
color: #000080;
|
||||
font-weight: normal;
|
||||
background-color: #e8eef2;
|
||||
}
|
||||
TD.tiny { font-size: 75%;
|
||||
}
|
||||
a {
|
||||
color: #1A41A8;
|
||||
}
|
||||
a:visited {
|
||||
color: #2A3798;
|
||||
}
|
||||
.dirtab { padding: 4px;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #84b0c7;
|
||||
}
|
||||
TH.dirtab { background: #e8eef2;
|
||||
font-weight: bold;
|
||||
}
|
||||
HR { height: 1px;
|
||||
border: none;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,31 @@
|
|||
<!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.4: File Index</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="current"><a href="files.html"><span>File List</span></a></li>
|
||||
<li><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<h1>The Protothreads Library 1.4 File List</h1>Here is a list of all documented files with brief descriptions:<table>
|
||||
<tr><td class="indexkey"><a class="el" href="a00009.html">lc-addrlabels.h</a> <a href="a00018.html">[code]</a></td><td class="indexvalue">Implementation of local continuations based on the "Labels as values" feature of gcc </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="a00010.html">lc-switch.h</a> <a href="a00019.html">[code]</a></td><td class="indexvalue">Implementation of local continuations based on switch() statment </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="a00011.html">lc.h</a> <a href="a00020.html">[code]</a></td><td class="indexvalue">Local continuations </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="a00012.html">pt-sem.h</a> <a href="a00021.html">[code]</a></td><td class="indexvalue">Couting semaphores implemented on protothreads </td></tr>
|
||||
<tr><td class="indexkey"><a class="el" href="a00013.html">pt.h</a> <a href="a00022.html">[code]</a></td><td class="indexvalue">Protothreads implementation </td></tr>
|
||||
</table>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
After Width: | Height: | Size: 174 B |
After Width: | Height: | Size: 255 B |
After Width: | Height: | Size: 259 B |
After Width: | Height: | Size: 261 B |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 358 B |
After Width: | Height: | Size: 160 B |
After Width: | Height: | Size: 194 B |
After Width: | Height: | Size: 235 B |
After Width: | Height: | Size: 165 B |
After Width: | Height: | Size: 200 B |
After Width: | Height: | Size: 229 B |
|
@ -0,0 +1,37 @@
|
|||
<!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.4: Data Fields</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li id="current"><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="current"><a href="functions.html"><span>All</span></a></li>
|
||||
<li><a href="functions_vars.html"><span>Variables</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
|
||||
<p>
|
||||
<ul>
|
||||
<li>count
|
||||
: <a class="el" href="a00006.html#6f341120f42d5fd9f329ff1119594743">pt_sem</a><li>lc
|
||||
: <a class="el" href="a00005.html#c3fa0fa86689e3e7c039a16c16861dbe">pt</a></ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,37 @@
|
|||
<!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.4: Data Fields - Variables</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li id="current"><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="functions.html"><span>All</span></a></li>
|
||||
<li id="current"><a href="functions_vars.html"><span>Variables</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>count
|
||||
: <a class="el" href="a00006.html#6f341120f42d5fd9f329ff1119594743">pt_sem</a><li>lc
|
||||
: <a class="el" href="a00005.html#c3fa0fa86689e3e7c039a16c16861dbe">pt</a></ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,62 @@
|
|||
<!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.4: Data Fields</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li id="current"><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li id="current"><a href="globals.html"><span>All</span></a></li>
|
||||
<li><a href="globals_type.html"><span>Typedefs</span></a></li>
|
||||
<li><a href="globals_defs.html"><span>Defines</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
|
||||
<p>
|
||||
<ul>
|
||||
<li>LC_CONCAT
|
||||
: <a class="el" href="a00017.html#g2b1f9b9fe8b6895b156f0af10538971c">lc-addrlabels.h</a><li>LC_CONCAT2
|
||||
: <a class="el" href="a00017.html#g6e1e879e172e2d8838e5f567dac8918c">lc-addrlabels.h</a><li>LC_END
|
||||
: <a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">lc-switch.h</a>, <a class="el" href="a00017.html#g3d76802e55349cc8bf74f286ced203c3">lc.h</a><li>LC_INIT
|
||||
: <a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">lc-addrlabels.h</a>, <a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">lc-switch.h</a>, <a class="el" href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76">lc.h</a><li>LC_RESUME
|
||||
: <a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">lc-addrlabels.h</a>, <a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">lc-switch.h</a>, <a class="el" href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3">lc.h</a><li>LC_SET
|
||||
: <a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">lc-switch.h</a>, <a class="el" href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341">lc.h</a><li>lc_t
|
||||
: <a class="el" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc-switch.h</a><li>PT_BEGIN
|
||||
: <a class="el" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">pt.h</a><li>PT_END
|
||||
: <a class="el" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">pt.h</a><li>PT_ENDED
|
||||
: <a class="el" href="a00014.html#g9ff1e8936a8a26bff54c05f8a989b93b">pt.h</a><li>PT_EXIT
|
||||
: <a class="el" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">pt.h</a><li>PT_EXITED
|
||||
: <a class="el" href="a00014.html#gcfae9053e5c107a1aed6b228c917d2ea">pt.h</a><li>PT_INIT
|
||||
: <a class="el" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">pt.h</a><li>PT_RESTART
|
||||
: <a class="el" href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">pt.h</a><li>PT_SCHEDULE
|
||||
: <a class="el" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">pt.h</a><li>PT_SEM_INIT
|
||||
: <a class="el" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">pt-sem.h</a><li>PT_SEM_SIGNAL
|
||||
: <a class="el" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">pt-sem.h</a><li>PT_SEM_WAIT
|
||||
: <a class="el" href="a00016.html#g386ff87a52a840512906f2940e229e2e">pt-sem.h</a><li>PT_SPAWN
|
||||
: <a class="el" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">pt.h</a><li>PT_THREAD
|
||||
: <a class="el" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">pt.h</a><li>PT_WAIT_THREAD
|
||||
: <a class="el" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">pt.h</a><li>PT_WAIT_UNTIL
|
||||
: <a class="el" href="a00014.html#g99e43010ec61327164466aa2d902de45">pt.h</a><li>PT_WAIT_WHILE
|
||||
: <a class="el" href="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d">pt.h</a><li>PT_WAITING
|
||||
: <a class="el" href="a00014.html#g7b5319b5b65761a845fcd1500fde4cdc">pt.h</a><li>PT_YIELD
|
||||
: <a class="el" href="a00014.html#g155cba6121323726d02c00284428fed6">pt.h</a><li>PT_YIELD_UNTIL
|
||||
: <a class="el" href="a00014.html#ge3c821e3a388615528efda9d23c7d115">pt.h</a><li>PT_YIELDED
|
||||
: <a class="el" href="a00014.html#ge469332907e0617d72d5e2dd4297119d">pt.h</a></ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,61 @@
|
|||
<!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.4: Data Fields</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li id="current"><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="globals.html"><span>All</span></a></li>
|
||||
<li><a href="globals_type.html"><span>Typedefs</span></a></li>
|
||||
<li id="current"><a href="globals_defs.html"><span>Defines</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>LC_CONCAT
|
||||
: <a class="el" href="a00017.html#g2b1f9b9fe8b6895b156f0af10538971c">lc-addrlabels.h</a><li>LC_CONCAT2
|
||||
: <a class="el" href="a00017.html#g6e1e879e172e2d8838e5f567dac8918c">lc-addrlabels.h</a><li>LC_END
|
||||
: <a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gca51ceb2f5d855dfde55bcedf8d3b92d">lc-switch.h</a>, <a class="el" href="a00017.html#g3d76802e55349cc8bf74f286ced203c3">lc.h</a><li>LC_INIT
|
||||
: <a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">lc-addrlabels.h</a>, <a class="el" href="a00017.html#g2c1bb4fa6d7a6ff951a41c73fc721109">lc-switch.h</a>, <a class="el" href="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76">lc.h</a><li>LC_RESUME
|
||||
: <a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">lc-addrlabels.h</a>, <a class="el" href="a00017.html#g1ec8b8f4710dce1fa7fb87d3a31541ae">lc-switch.h</a>, <a class="el" href="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3">lc.h</a><li>LC_SET
|
||||
: <a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gd8eec328a4868d767f0c00c8d1c6cfc1">lc-switch.h</a>, <a class="el" href="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341">lc.h</a><li>PT_BEGIN
|
||||
: <a class="el" href="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc">pt.h</a><li>PT_END
|
||||
: <a class="el" href="a00014.html#g7b04a0035bef29d905496c23bae066d2">pt.h</a><li>PT_ENDED
|
||||
: <a class="el" href="a00014.html#g9ff1e8936a8a26bff54c05f8a989b93b">pt.h</a><li>PT_EXIT
|
||||
: <a class="el" href="a00014.html#g905451249dca72ce0385bf2a9ff178ee">pt.h</a><li>PT_EXITED
|
||||
: <a class="el" href="a00014.html#gcfae9053e5c107a1aed6b228c917d2ea">pt.h</a><li>PT_INIT
|
||||
: <a class="el" href="a00014.html#ge6bae7dc0225468c8a5ac269df549892">pt.h</a><li>PT_RESTART
|
||||
: <a class="el" href="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab">pt.h</a><li>PT_SCHEDULE
|
||||
: <a class="el" href="a00014.html#gfa82b860a64b67d25ab3abc21811896f">pt.h</a><li>PT_SEM_INIT
|
||||
: <a class="el" href="a00016.html#gd7089c5dc86f12019f0361d82a75b04b">pt-sem.h</a><li>PT_SEM_SIGNAL
|
||||
: <a class="el" href="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19">pt-sem.h</a><li>PT_SEM_WAIT
|
||||
: <a class="el" href="a00016.html#g386ff87a52a840512906f2940e229e2e">pt-sem.h</a><li>PT_SPAWN
|
||||
: <a class="el" href="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae">pt.h</a><li>PT_THREAD
|
||||
: <a class="el" href="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">pt.h</a><li>PT_WAIT_THREAD
|
||||
: <a class="el" href="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c">pt.h</a><li>PT_WAIT_UNTIL
|
||||
: <a class="el" href="a00014.html#g99e43010ec61327164466aa2d902de45">pt.h</a><li>PT_WAIT_WHILE
|
||||
: <a class="el" href="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d">pt.h</a><li>PT_WAITING
|
||||
: <a class="el" href="a00014.html#g7b5319b5b65761a845fcd1500fde4cdc">pt.h</a><li>PT_YIELD
|
||||
: <a class="el" href="a00014.html#g155cba6121323726d02c00284428fed6">pt.h</a><li>PT_YIELD_UNTIL
|
||||
: <a class="el" href="a00014.html#ge3c821e3a388615528efda9d23c7d115">pt.h</a><li>PT_YIELDED
|
||||
: <a class="el" href="a00014.html#ge469332907e0617d72d5e2dd4297119d">pt.h</a></ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,36 @@
|
|||
<!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.4: Data Fields</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
<li id="current"><a href="globals.html"><span>Globals</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="globals.html"><span>All</span></a></li>
|
||||
<li id="current"><a href="globals_type.html"><span>Typedefs</span></a></li>
|
||||
<li><a href="globals_defs.html"><span>Defines</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>lc_t
|
||||
: <a class="el" href="a00017.html#g2bdc4b7b4038454a79f1b2a94a6d2a98">lc-addrlabels.h</a>, <a class="el" href="a00017.html#gfad6704adb116cc16edb80f744e7239d">lc-switch.h</a></ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,29 @@
|
|||
<!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.4: Hierarchical Index</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 Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li id="current"><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li id="current"><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
||||
<li><a href="functions.html"><span>Data Fields</span></a></li>
|
||||
</ul></div>
|
||||
<h1>The Protothreads Library 1.4 Class Hierarchy</h1>This inheritance list is sorted roughly, but not completely, alphabetically:<ul>
|
||||
<li><a class="el" href="a00005.html">pt</a>
|
||||
<li><a class="el" href="a00006.html">pt_sem</a>
|
||||
</ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<HTML><HEAD></HEAD><BODY>
|
||||
<OBJECT type="text/site properties">
|
||||
<param name="FrameName" value="right">
|
||||
</OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="The Protothreads Library"><param name="Local" value="main.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="File List"><param name="Local" value="files.html"><param name="ImageNumber" value="1"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="lc-addrlabels.h"><param name="Local" value="a00009.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="lc-switch.h"><param name="Local" value="a00010.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="lc.h"><param name="Local" value="a00011.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt-sem.h"><param name="Local" value="a00012.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt.h"><param name="Local" value="a00013.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Data Structures"><param name="Local" value="annotated.html"><param name="ImageNumber" value="1"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt"><param name="Local" value="a00005.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt_sem"><param name="Local" value="a00006.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Class Hierarchy"><param name="Local" value="hierarchy.html"><param name="ImageNumber" value="1"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt"><param name="Local" value="a00005.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="pt_sem"><param name="Local" value="a00006.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Data Fields"><param name="Local" value="functions.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Modules"><param name="Local" value="modules.html"><param name="ImageNumber" value="1"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Protothreads"><param name="Local" value="a00014.html"><param name="ImageNumber" value="1"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Protothread semaphores"><param name="Local" value="a00016.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<UL>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Local continuations"><param name="Local" value="a00017.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<UL>
|
||||
</UL>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Examples"><param name="Local" value="a00015.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
<UL>
|
||||
</UL>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Name" value="Globals"><param name="Local" value="globals.html"><param name="ImageNumber" value="11"></OBJECT>
|
||||
</UL>
|
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<HTML><HEAD></HEAD><BODY>
|
||||
<OBJECT type="text/site properties">
|
||||
<param name="FrameName" value="right">
|
||||
</OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g3d76802e55349cc8bf74f286ced203c3"><param name="Name" value="LC_END"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76"><param name="Name" value="LC_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3"><param name="Name" value="LC_RESUME"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341"><param name="Name" value="LC_SET"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html"><param name="Name" value="Local continuations"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g3d76802e55349cc8bf74f286ced203c3"><param name="Name" value="LC_END"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g9ca9d0fef02b9c5d93bed2834e7aeb76"><param name="Name" value="LC_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#g33dad6011c98dfeb4e64fee1d6892cb3"><param name="Name" value="LC_RESUME"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00017.html#gfb1d5e671e40464a7a7bda589b5d4341"><param name="Name" value="LC_SET"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html"><param name="Name" value="Protothread semaphores"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#gd7089c5dc86f12019f0361d82a75b04b"><param name="Name" value="PT_SEM_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19"><param name="Name" value="PT_SEM_SIGNAL"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#g386ff87a52a840512906f2940e229e2e"><param name="Name" value="PT_SEM_WAIT"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html"><param name="Name" value="Protothreads"></OBJECT>
|
||||
<UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc"><param name="Name" value="PT_BEGIN"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g7b04a0035bef29d905496c23bae066d2"><param name="Name" value="PT_END"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g905451249dca72ce0385bf2a9ff178ee"><param name="Name" value="PT_EXIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#ge6bae7dc0225468c8a5ac269df549892"><param name="Name" value="PT_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab"><param name="Name" value="PT_RESTART"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gfa82b860a64b67d25ab3abc21811896f"><param name="Name" value="PT_SCHEDULE"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae"><param name="Name" value="PT_SPAWN"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901"><param name="Name" value="PT_THREAD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c"><param name="Name" value="PT_WAIT_THREAD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g99e43010ec61327164466aa2d902de45"><param name="Name" value="PT_WAIT_UNTIL"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d"><param name="Name" value="PT_WAIT_WHILE"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g155cba6121323726d02c00284428fed6"><param name="Name" value="PT_YIELD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#ge3c821e3a388615528efda9d23c7d115"><param name="Name" value="PT_YIELD_UNTIL"></OBJECT>
|
||||
</UL>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g2ffbb9e554e08a343ae2f9de4bedfdfc"><param name="Name" value="PT_BEGIN"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g7b04a0035bef29d905496c23bae066d2"><param name="Name" value="PT_END"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g905451249dca72ce0385bf2a9ff178ee"><param name="Name" value="PT_EXIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#ge6bae7dc0225468c8a5ac269df549892"><param name="Name" value="PT_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gcd3ac045f0a4ae63412e3b3d8780e8ab"><param name="Name" value="PT_RESTART"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gfa82b860a64b67d25ab3abc21811896f"><param name="Name" value="PT_SCHEDULE"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#gd7089c5dc86f12019f0361d82a75b04b"><param name="Name" value="PT_SEM_INIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#g1eaaf4d9d75e24582acc6440d7085f19"><param name="Name" value="PT_SEM_SIGNAL"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00016.html#g386ff87a52a840512906f2940e229e2e"><param name="Name" value="PT_SEM_WAIT"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g9e97a0b4d5cc7764d8e19758f5da53ae"><param name="Name" value="PT_SPAWN"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g3d4c8bd4aada659eb34f5d2ffd3e7901"><param name="Name" value="PT_THREAD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g2f8f70c30b9ee08a103fbd69a4365c4c"><param name="Name" value="PT_WAIT_THREAD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g99e43010ec61327164466aa2d902de45"><param name="Name" value="PT_WAIT_UNTIL"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#gad14bbbf092b90aa0a5a4f9169504a8d"><param name="Name" value="PT_WAIT_WHILE"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#g155cba6121323726d02c00284428fed6"><param name="Name" value="PT_YIELD"></OBJECT>
|
||||
<LI><OBJECT type="text/sitemap"><param name="Local" value="a00014.html#ge3c821e3a388615528efda9d23c7d115"><param name="Name" value="PT_YIELD_UNTIL"></OBJECT>
|
||||
</UL>
|
|
@ -0,0 +1,44 @@
|
|||
[OPTIONS]
|
||||
Compatibility=1.1
|
||||
Full-text search=Yes
|
||||
Contents file=index.hhc
|
||||
Default Window=main
|
||||
Default topic=main.html
|
||||
Index file=index.hhk
|
||||
Language=0x409 English (United States)
|
||||
Title=The Protothreads Library 1.4
|
||||
|
||||
[WINDOWS]
|
||||
main="The Protothreads Library 1.4","index.hhc","index.hhk","main.html","main.html",,,,,0x23520,,0x387e,,,,,,,,0
|
||||
|
||||
[FILES]
|
||||
main.html
|
||||
files.html
|
||||
a00018.html
|
||||
a00019.html
|
||||
a00020.html
|
||||
a00021.html
|
||||
a00022.html
|
||||
a00009.html
|
||||
a00010.html
|
||||
a00011.html
|
||||
a00012.html
|
||||
a00013.html
|
||||
annotated.html
|
||||
hierarchy.html
|
||||
functions.html
|
||||
functions_vars.html
|
||||
a00005.html
|
||||
a00006.html
|
||||
a00014.html
|
||||
a00015.html
|
||||
a00016.html
|
||||
a00017.html
|
||||
modules.html
|
||||
globals.html
|
||||
globals_type.html
|
||||
globals_defs.html
|
||||
tabs.css
|
||||
tab_b.gif
|
||||
tab_l.gif
|
||||
tab_r.gif
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
||||
<title>The Protothreads Library 1.4</title></head>
|
||||
<frameset cols="250,*">
|
||||
<frame src="tree.html" name="treefrm">
|
||||
<frame src="main.html" name="basefrm">
|
||||
</frameset>
|
||||
</html>
|
|
@ -0,0 +1,81 @@
|
|||
<!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.4: The Protothreads Library</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 id="current"><a href="main.html"><span>Main Page</span></a></li>
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<h1>The Protothreads Library</h1>
|
||||
<p>
|
||||
<dl compact><dt><b>Author:</b></dt><dd>Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>></dd></dl>
|
||||
Protothreads are a type of lightweight stackless threads designed for severly memory constrained systems such as deeply embedded systems or sensor network nodes. 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>
|
||||
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>
|
||||
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="a00015.html">Example programs</a> <p>
|
||||
<a class="el" href="a00014.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.<p>
|
||||
More information and new version of the code can be found at the Protothreads homepage:<p>
|
||||
<a href="http://www.sics.se/~adam/pt/">http://www.sics.se/~adam/pt/</a><h2><a class="anchor" name="authors">
|
||||
Authors</a></h2>
|
||||
The protothreads library was written by Adam Dunkels <<a href="mailto:adam@sics.se">adam@sics.se</a>> with support from Oliver Schmidt <<a href="mailto:ol.sc@web.de">ol.sc@web.de</a>>.<h2><a class="anchor" name="using">
|
||||
Using protothreads</a></h2>
|
||||
Using protothreads in a project is easy: simply copy the files <a class="el" href="a00013.html">pt.h</a>, <a class="el" href="a00011.html">lc.h</a> and lc-switch.h into the include files directory of the project, and #include "pt.h" in all files that should use protothreads.<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 local continuations. 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: a protothread cannot perform a blocking wait (<a class="el" href="a00014.html#g99e43010ec61327164466aa2d902de45">PT_WAIT_UNTIL()</a> or <a class="el" href="a00014.html#g155cba6121323726d02c00284428fed6">PT_YIELD()</a>) inside a switch() statement.<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. <hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
|
@ -0,0 +1,27 @@
|
|||
<!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.4: Module Index</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 Page</span></a></li>
|
||||
<li id="current"><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||||
<li><a href="files.html"><span>Files</span></a></li>
|
||||
</ul></div>
|
||||
<h1>The Protothreads Library 1.4 Modules</h1>Here is a list of all modules:<ul>
|
||||
<li><a class="el" href="a00014.html">Protothreads</a>
|
||||
<ul>
|
||||
<li><a class="el" href="a00016.html">Protothread semaphores</a>
|
||||
<li><a class="el" href="a00017.html">Local continuations</a>
|
||||
</ul>
|
||||
<li><a class="el" href="a00015.html">Examples</a>
|
||||
</ul>
|
||||
<hr size="1"><address style="align: right;"><small>Generated on Mon Oct 2 10:06:29 2006 for The Protothreads Library 1.4 by
|
||||
<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>
|
After Width: | Height: | Size: 35 B |
After Width: | Height: | Size: 706 B |
After Width: | Height: | Size: 2.5 KiB |
|
@ -0,0 +1,102 @@
|
|||
/* tabs styles, based on http://www.alistapart.com/articles/slidingdoors */
|
||||
|
||||
DIV.tabs
|
||||
{
|
||||
float : left;
|
||||
width : 100%;
|
||||
background : url("tab_b.gif") repeat-x bottom;
|
||||
margin-bottom : 4px;
|
||||
}
|
||||
|
||||
DIV.tabs UL
|
||||
{
|
||||
margin : 0px;
|
||||
padding-left : 10px;
|
||||
list-style : none;
|
||||
}
|
||||
|
||||
DIV.tabs LI, DIV.tabs FORM
|
||||
{
|
||||
display : inline;
|
||||
margin : 0px;
|
||||
padding : 0px;
|
||||
}
|
||||
|
||||
DIV.tabs FORM
|
||||
{
|
||||
float : right;
|
||||
}
|
||||
|
||||
DIV.tabs A
|
||||
{
|
||||
float : left;
|
||||
background : url("tab_r.gif") no-repeat right top;
|
||||
border-bottom : 1px solid #84B0C7;
|
||||
font-size : x-small;
|
||||
font-weight : bold;
|
||||
text-decoration : none;
|
||||
}
|
||||
|
||||
DIV.tabs A:hover
|
||||
{
|
||||
background-position: 100% -150px;
|
||||
}
|
||||
|
||||
DIV.tabs A:link, DIV.tabs A:visited,
|
||||
DIV.tabs A:active, DIV.tabs A:hover
|
||||
{
|
||||
color: #1A419D;
|
||||
}
|
||||
|
||||
DIV.tabs SPAN
|
||||
{
|
||||
float : left;
|
||||
display : block;
|
||||
background : url("tab_l.gif") no-repeat left top;
|
||||
padding : 5px 9px;
|
||||
white-space : nowrap;
|
||||
}
|
||||
|
||||
DIV.tabs INPUT
|
||||
{
|
||||
float : right;
|
||||
display : inline;
|
||||
font-size : 1em;
|
||||
}
|
||||
|
||||
DIV.tabs TD
|
||||
{
|
||||
font-size : x-small;
|
||||
font-weight : bold;
|
||||
text-decoration : none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Commented Backslash Hack hides rule from IE5-Mac \*/
|
||||
DIV.tabs SPAN {float : none;}
|
||||
/* End IE5-Mac hack */
|
||||
|
||||
DIV.tabs A:hover SPAN
|
||||
{
|
||||
background-position: 0% -150px;
|
||||
}
|
||||
|
||||
DIV.tabs LI#current A
|
||||
{
|
||||
background-position: 100% -150px;
|
||||
border-width : 0px;
|
||||
}
|
||||
|
||||
DIV.tabs LI#current SPAN
|
||||
{
|
||||
background-position: 0% -150px;
|
||||
padding-bottom : 6px;
|
||||
}
|
||||
|
||||
DIV.nav
|
||||
{
|
||||
background : none;
|
||||
border : none;
|
||||
border-bottom : 1px solid #84B0C7;
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=iso-8859-1" />
|
||||
<meta http-equiv="Content-Style-Type" content="text/css" />
|
||||
<meta http-equiv="Content-Language" content="en" />
|
||||
<link rel="stylesheet" href="doxygen.css">
|
||||
<title>TreeView</title>
|
||||
<style type="text/css">
|
||||
<!--
|
||||
.directory { font-size: 10pt; font-weight: bold; }
|
||||
.directory h3 { margin: 0px; margin-top: 1em; font-size: 11pt; }
|
||||
.directory p { margin: 0px; white-space: nowrap; }
|
||||
.directory div { display: none; margin: 0px; }
|
||||
.directory img { vertical-align: middle; }
|
||||
-->
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
<!-- // Hide script from old browsers
|
||||
|
||||
function toggleFolder(id, imageNode)
|
||||
{
|
||||
var folder = document.getElementById(id);
|
||||
var l = imageNode.src.length;
|
||||
if (imageNode.src.substring(l-20,l)=="ftv2folderclosed.png" ||
|
||||
imageNode.src.substring(l-18,l)=="ftv2folderopen.png")
|
||||
{
|
||||
imageNode = imageNode.previousSibling;
|
||||
l = imageNode.src.length;
|
||||
}
|
||||
if (folder == null)
|
||||
{
|
||||
}
|
||||
else if (folder.style.display == "block")
|
||||
{
|
||||
if (imageNode != null)
|
||||
{
|
||||
imageNode.nextSibling.src = "ftv2folderclosed.png";
|
||||
if (imageNode.src.substring(l-13,l) == "ftv2mnode.png")
|
||||
{
|
||||
imageNode.src = "ftv2pnode.png";
|
||||
}
|
||||
else if (imageNode.src.substring(l-17,l) == "ftv2mlastnode.png")
|
||||
{
|
||||
imageNode.src = "ftv2plastnode.png";
|
||||
}
|
||||
}
|
||||
folder.style.display = "none";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (imageNode != null)
|
||||
{
|
||||
imageNode.nextSibling.src = "ftv2folderopen.png";
|
||||
if (imageNode.src.substring(l-13,l) == "ftv2pnode.png")
|
||||
{
|
||||
imageNode.src = "ftv2mnode.png";
|
||||
}
|
||||
else if (imageNode.src.substring(l-17,l) == "ftv2plastnode.png")
|
||||
{
|
||||
imageNode.src = "ftv2mlastnode.png";
|
||||
}
|
||||
}
|
||||
folder.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
// End script hiding -->
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="directory">
|
||||
<h3>The Protothreads Library 1.4</h3>
|
||||
<div style="display: block;">
|
||||
<p><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="main.html" target="basefrm">The Protothreads Library</a></p>
|
||||
<p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder1', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder1', this)"/><a class="el" href="files.html" target="basefrm">File List</a></p>
|
||||
<div id="folder1">
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00009.html" target="basefrm">lc-addrlabels.h</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00010.html" target="basefrm">lc-switch.h</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00011.html" target="basefrm">lc.h</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00012.html" target="basefrm">pt-sem.h</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00013.html" target="basefrm">pt.h</a></p>
|
||||
</div>
|
||||
<p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder2', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder2', this)"/><a class="el" href="annotated.html" target="basefrm">Data Structures</a></p>
|
||||
<div id="folder2">
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00005.html" target="basefrm">pt</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00006.html" target="basefrm">pt_sem</a></p>
|
||||
</div>
|
||||
<p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder3', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder3', this)"/><a class="el" href="hierarchy.html" target="basefrm">Class Hierarchy</a></p>
|
||||
<div id="folder3">
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00005.html" target="basefrm">pt</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00006.html" target="basefrm">pt_sem</a></p>
|
||||
</div>
|
||||
<p><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="functions.html" target="basefrm">Data Fields</a></p>
|
||||
<p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder4', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder4', this)"/><a class="el" href="modules.html" target="basefrm">Modules</a></p>
|
||||
<div id="folder4">
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder5', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder5', this)"/><a class="el" href="a00014.html" target="basefrm">Protothreads</a></p>
|
||||
<div id="folder5">
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00016.html" target="basefrm">Protothread semaphores</a></p>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00017.html" target="basefrm">Local continuations</a></p>
|
||||
</div>
|
||||
<p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="a00015.html" target="basefrm">Examples</a></p>
|
||||
</div>
|
||||
<p><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="globals.html" target="basefrm">Globals</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
\defgroup pt Protothreads
|
||||
@{
|
||||
Protothreads are implemented in a single header file, pt.h, which
|
||||
includes the local continuations header file, lc.h. This file in turn
|
||||
includes the actual implementation of local continuations, which
|
||||
typically also is contained in a single header file.
|
||||
|
||||
*/
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
\defgroup examples Examples
|
||||
@{
|
||||
|
||||
\section example-small A small example
|
||||
|
||||
This first example shows a very simple program: two protothreads
|
||||
waiting for each other to toggle two flags. The code illustrates how
|
||||
to write protothreads code, how to initialize protothreads, and how to
|
||||
schedule them.
|
||||
|
||||
\include example-small.c
|
||||
|
||||
|
||||
\section example-code-lock A code-lock
|
||||
This example shows how to implement a simple code lock - the kind of
|
||||
device that is placed next to doors and that you have to push a four
|
||||
digit number into in order to unlock the door.
|
||||
|
||||
The code lock waits for key presses from a numeric keyboard and if the
|
||||
correct code is entered, the lock is unlocked. There is a maximum time
|
||||
of one second between each key press, and after the correct code has
|
||||
been entered, no more keys must be pressed for 0.5 seconds before the
|
||||
lock is opened.
|
||||
|
||||
\include example-codelock.c
|
||||
|
||||
\section example-buffer The bounded buffer with protothread semaphores
|
||||
|
||||
The following example shows how to implement the bounded buffer
|
||||
problem using the protothreads semaphore library. The example uses
|
||||
three protothreads: one producer() protothread that produces items,
|
||||
one consumer() protothread that consumes items, and one
|
||||
driver_thread() that schedules the producer and consumer protothreads.
|
||||
|
||||
Note that there is no need for a mutex to guard the add_to_buffer()
|
||||
and get_from_buffer() functions because of the implicit locking
|
||||
semantics of protothreads - a protothread will never be preempted and
|
||||
will never block except in an explicit PT_WAIT statement.
|
||||
|
||||
\include example-buffer.c
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @} */
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
|
||||
\mainpage The Protothreads Library
|
||||
|
||||
\author Adam Dunkels <adam@sics.se>
|
||||
|
||||
Protothreads are a type of lightweight stackless threads designed for
|
||||
severly memory constrained systems such as deeply embedded systems or
|
||||
sensor network nodes. Protothreads provides linear code execution for
|
||||
event-driven systems implemented in C. Protothreads can be used with
|
||||
or without an RTOS.
|
||||
|
||||
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.
|
||||
|
||||
Main features:
|
||||
|
||||
- No machine specific code - the protothreads library is pure C
|
||||
|
||||
- Does not use error-prone functions such as longjmp()
|
||||
|
||||
- Very small RAM overhead - only two bytes per protothread
|
||||
|
||||
- Can be used with or without an OS
|
||||
|
||||
- Provides blocking wait without full multi-threading or
|
||||
stack-switching
|
||||
|
||||
Examples applications:
|
||||
|
||||
- Memory constrained systems
|
||||
|
||||
- Event-driven protocol stacks
|
||||
|
||||
- Deeply embedded systems
|
||||
|
||||
- Sensor network nodes
|
||||
|
||||
|
||||
\sa \ref examples "Example programs"
|
||||
\sa \ref pt "Protothreads API documentation"
|
||||
|
||||
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.
|
||||
|
||||
More information and new version of the code can be found at the
|
||||
Protothreads homepage:
|
||||
|
||||
http://www.sics.se/~adam/pt/
|
||||
|
||||
\section authors Authors
|
||||
|
||||
The protothreads library was written by Adam Dunkels <adam@sics.se>
|
||||
with support from Oliver Schmidt <ol.sc@web.de>.
|
||||
|
||||
\section using Using protothreads
|
||||
|
||||
Using protothreads in a project is easy: simply copy the files pt.h,
|
||||
lc.h and lc-switch.h into the include files directory of the project,
|
||||
and \#include "pt.h" in all files that should use protothreads.
|
||||
|
||||
\section pt-desc Protothreads
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
\section pt-autovars Local variables
|
||||
|
||||
\note
|
||||
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!
|
||||
|
||||
\section pt-scheduling Scheduling
|
||||
|
||||
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.
|
||||
|
||||
\section pt-impl Implementation
|
||||
|
||||
Protothreads are implemented using local continuations. 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.
|
||||
|
||||
|
||||
Local continuations can be implemented in a variety of ways:
|
||||
|
||||
-# by using machine specific assembler code,
|
||||
-# by using standard C constructs, or
|
||||
-# by using compiler extensions.
|
||||
|
||||
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.
|
||||
|
||||
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: a
|
||||
protothread cannot perform a blocking wait (PT_WAIT_UNTIL() or
|
||||
PT_YIELD()) inside a switch() statement.
|
||||
|
||||
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.
|
||||
|
||||
*/
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the protothreads library.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: example-buffer.c,v 1.5 2005/10/07 05:21:33 adam Exp $
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pt-sem.h"
|
||||
|
||||
#define NUM_ITEMS 32
|
||||
#define BUFSIZE 8
|
||||
|
||||
static int buffer[BUFSIZE];
|
||||
static int bufptr;
|
||||
|
||||
static void
|
||||
add_to_buffer(int item)
|
||||
{
|
||||
printf("Item %d added to buffer at place %d\n", item, bufptr);
|
||||
buffer[bufptr] = item;
|
||||
bufptr = (bufptr + 1) % BUFSIZE;
|
||||
}
|
||||
static int
|
||||
get_from_buffer(void)
|
||||
{
|
||||
int item;
|
||||
item = buffer[bufptr];
|
||||
printf("Item %d retrieved from buffer at place %d\n",
|
||||
item, bufptr);
|
||||
bufptr = (bufptr + 1) % BUFSIZE;
|
||||
return item;
|
||||
}
|
||||
|
||||
static int
|
||||
produce_item(void)
|
||||
{
|
||||
static int item = 0;
|
||||
printf("Item %d produced\n", item);
|
||||
return item++;
|
||||
}
|
||||
|
||||
static void
|
||||
consume_item(int item)
|
||||
{
|
||||
printf("Item %d consumed\n", item);
|
||||
}
|
||||
|
||||
static struct pt_sem full, empty;
|
||||
|
||||
static
|
||||
PT_THREAD(producer(struct pt *pt))
|
||||
{
|
||||
static int produced;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
for(produced = 0; produced < NUM_ITEMS; ++produced) {
|
||||
|
||||
PT_SEM_WAIT(pt, &full);
|
||||
|
||||
add_to_buffer(produce_item());
|
||||
|
||||
PT_SEM_SIGNAL(pt, &empty);
|
||||
}
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
static
|
||||
PT_THREAD(consumer(struct pt *pt))
|
||||
{
|
||||
static int consumed;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
for(consumed = 0; consumed < NUM_ITEMS; ++consumed) {
|
||||
|
||||
PT_SEM_WAIT(pt, &empty);
|
||||
|
||||
consume_item(get_from_buffer());
|
||||
|
||||
PT_SEM_SIGNAL(pt, &full);
|
||||
}
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
static
|
||||
PT_THREAD(driver_thread(struct pt *pt))
|
||||
{
|
||||
static struct pt pt_producer, pt_consumer;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
PT_SEM_INIT(&empty, 0);
|
||||
PT_SEM_INIT(&full, BUFSIZE);
|
||||
|
||||
PT_INIT(&pt_producer);
|
||||
PT_INIT(&pt_consumer);
|
||||
|
||||
PT_WAIT_THREAD(pt, producer(&pt_producer) &
|
||||
consumer(&pt_consumer));
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct pt driver_pt;
|
||||
|
||||
PT_INIT(&driver_pt);
|
||||
|
||||
while(PT_SCHEDULE(driver_thread(&driver_pt))) {
|
||||
|
||||
/*
|
||||
* When running this example on a multitasking system, we must
|
||||
* give other processes a chance to run too and therefore we call
|
||||
* usleep() resp. Sleep() here. On a dedicated embedded system,
|
||||
* we usually do not need to do this.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
Sleep(0);
|
||||
#else
|
||||
usleep(10);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,414 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the protothreads library.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: example-codelock.c,v 1.5 2005/10/06 07:57:08 adam Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This example shows how to implement a simple code lock. The code
|
||||
* lock waits for key presses from a numeric keyboard and if the
|
||||
* correct code is entered, the lock is unlocked. There is a maximum
|
||||
* time of one second between each key press, and after the correct
|
||||
* code has been entered, no more keys must be pressed for 0.5 seconds
|
||||
* before the lock is opened.
|
||||
*
|
||||
* This is an example that shows two things:
|
||||
* - how to implement a code lock key input mechanism, and
|
||||
* - how to implement a sequential timed routine.
|
||||
*
|
||||
* The program consists of two protothreads, one that implements the
|
||||
* code lock reader and one that implements simulated keyboard input.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "pt.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* The following definitions are just for the simple timer library
|
||||
* used in this example. The actual implementation of the functions
|
||||
* can be found at the end of this file.
|
||||
*/
|
||||
struct timer { int start, interval; };
|
||||
static int timer_expired(struct timer *t);
|
||||
static void timer_set(struct timer *t, int usecs);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This example uses two timers: one for the code lock protothread and
|
||||
* one for the simulated key input protothread.
|
||||
*/
|
||||
static struct timer codelock_timer, input_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This is the code that has to be entered.
|
||||
*/
|
||||
static const char code[4] = {'1', '4', '2', '3'};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This example has two protothread and therefor has two protothread
|
||||
* control structures of type struct pt. These are initialized with
|
||||
* PT_INIT() in the main() function below.
|
||||
*/
|
||||
static struct pt codelock_pt, input_pt;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* The following code implements a simple key input. Input is made
|
||||
* with the press_key() function, and the function key_pressed()
|
||||
* checks if a key has been pressed. The variable "key" holds the
|
||||
* latest key that was pressed. The variable "key_pressed_flag" is set
|
||||
* when a key is pressed and cleared when a key press is checked.
|
||||
*/
|
||||
static char key, key_pressed_flag;
|
||||
|
||||
static void
|
||||
press_key(char k)
|
||||
{
|
||||
printf("--- Key '%c' pressed\n", k);
|
||||
key = k;
|
||||
key_pressed_flag = 1;
|
||||
}
|
||||
|
||||
static int
|
||||
key_pressed(void)
|
||||
{
|
||||
if(key_pressed_flag != 0) {
|
||||
key_pressed_flag = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Declaration of the protothread function implementing the code lock
|
||||
* logic. The protothread function is declared using the PT_THREAD()
|
||||
* macro. The function is declared with the "static" keyword since it
|
||||
* is local to this file. The name of the function is codelock_thread
|
||||
* and it takes one argument, pt, of the type struct pt.
|
||||
*
|
||||
*/
|
||||
static
|
||||
PT_THREAD(codelock_thread(struct pt *pt))
|
||||
{
|
||||
/* This is a local variable that holds the number of keys that have
|
||||
* been pressed. Note that it is declared with the "static" keyword
|
||||
* to make sure that the variable is *not* allocated on the stack.
|
||||
*/
|
||||
static int keys;
|
||||
|
||||
/*
|
||||
* Declare the beginning of the protothread.
|
||||
*/
|
||||
PT_BEGIN(pt);
|
||||
|
||||
/*
|
||||
* We'll let the protothread loop until the protothread is
|
||||
* expliticly exited with PT_EXIT().
|
||||
*/
|
||||
while(1) {
|
||||
|
||||
/*
|
||||
* We'll be reading key presses until we get the right amount of
|
||||
* correct keys.
|
||||
*/
|
||||
for(keys = 0; keys < sizeof(code); ++keys) {
|
||||
|
||||
/*
|
||||
* If we haven't gotten any keypresses, we'll simply wait for one.
|
||||
*/
|
||||
if(keys == 0) {
|
||||
|
||||
/*
|
||||
* The PT_WAIT_UNTIL() function will block until the condition
|
||||
* key_pressed() is true.
|
||||
*/
|
||||
PT_WAIT_UNTIL(pt, key_pressed());
|
||||
} else {
|
||||
|
||||
/*
|
||||
* If the "key" variable was larger than zero, we have already
|
||||
* gotten at least one correct key press. If so, we'll not
|
||||
* only wait for the next key, but we'll also set a timer that
|
||||
* expires in one second. This gives the person pressing the
|
||||
* keys one second to press the next key in the code.
|
||||
*/
|
||||
timer_set(&codelock_timer, 1000);
|
||||
|
||||
/*
|
||||
* The following statement shows how complex blocking
|
||||
* conditions can be easily expressed with protothreads and
|
||||
* the PT_WAIT_UNTIL() function.
|
||||
*/
|
||||
PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer));
|
||||
|
||||
/*
|
||||
* If the timer expired, we should break out of the for() loop
|
||||
* and start reading keys from the beginning of the while(1)
|
||||
* loop instead.
|
||||
*/
|
||||
if(timer_expired(&codelock_timer)) {
|
||||
printf("Code lock timer expired.\n");
|
||||
|
||||
/*
|
||||
* Break out from the for() loop and start from the
|
||||
* beginning of the while(1) loop.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the pressed key was correct.
|
||||
*/
|
||||
if(key != code[keys]) {
|
||||
printf("Incorrect key '%c' found\n", key);
|
||||
/*
|
||||
* Break out of the for() loop since the key was incorrect.
|
||||
*/
|
||||
break;
|
||||
} else {
|
||||
printf("Correct key '%c' found\n", key);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if we have gotten all keys.
|
||||
*/
|
||||
if(keys == sizeof(code)) {
|
||||
printf("Correct code entered, waiting for 500 ms before unlocking.\n");
|
||||
|
||||
/*
|
||||
* Ok, we got the correct code. But to make sure that the code
|
||||
* was not just a fluke of luck by an intruder, but the correct
|
||||
* code entered by a person that knows the correct code, we'll
|
||||
* wait for half a second before opening the lock. If another
|
||||
* key is pressed during this time, we'll assume that it was a
|
||||
* fluke of luck that the correct code was entered the first
|
||||
* time.
|
||||
*/
|
||||
timer_set(&codelock_timer, 500);
|
||||
PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer));
|
||||
|
||||
/*
|
||||
* If we continued from the PT_WAIT_UNTIL() statement without
|
||||
* the timer expired, we don't open the lock.
|
||||
*/
|
||||
if(!timer_expired(&codelock_timer)) {
|
||||
printf("Key pressed during final wait, code lock locked again.\n");
|
||||
} else {
|
||||
|
||||
/*
|
||||
* If the timer expired, we'll open the lock and exit from the
|
||||
* protothread.
|
||||
*/
|
||||
printf("Code lock unlocked.\n");
|
||||
PT_EXIT(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, we'll mark the end of the protothread.
|
||||
*/
|
||||
PT_END(pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This is the second protothread in this example. It implements a
|
||||
* simulated user pressing the keys. This illustrates how a linear
|
||||
* sequence of timed instructions can be implemented with
|
||||
* protothreads.
|
||||
*/
|
||||
static
|
||||
PT_THREAD(input_thread(struct pt *pt))
|
||||
{
|
||||
PT_BEGIN(pt);
|
||||
|
||||
printf("Waiting 1 second before entering first key.\n");
|
||||
|
||||
timer_set(&input_timer, 1000);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('1');
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('2');
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('3');
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('1');
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('4');
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('2');
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('3');
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('1');
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('4');
|
||||
|
||||
timer_set(&input_timer, 200);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('2');
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('3');
|
||||
|
||||
timer_set(&input_timer, 100);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('4');
|
||||
|
||||
timer_set(&input_timer, 1500);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('1');
|
||||
|
||||
timer_set(&input_timer, 300);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('4');
|
||||
|
||||
timer_set(&input_timer, 400);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('2');
|
||||
|
||||
timer_set(&input_timer, 500);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
press_key('3');
|
||||
|
||||
timer_set(&input_timer, 2000);
|
||||
PT_WAIT_UNTIL(pt, timer_expired(&input_timer));
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This is the main function. It initializes the two protothread
|
||||
* control structures and schedules the two protothreads. The main
|
||||
* function returns when the protothread the runs the code lock exits.
|
||||
*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/*
|
||||
* Initialize the two protothread control structures.
|
||||
*/
|
||||
PT_INIT(&input_pt);
|
||||
PT_INIT(&codelock_pt);
|
||||
|
||||
/*
|
||||
* Schedule the two protothreads until the codelock_thread() exits.
|
||||
*/
|
||||
while(PT_SCHEDULE(codelock_thread(&codelock_pt))) {
|
||||
PT_SCHEDULE(input_thread(&input_pt));
|
||||
|
||||
/*
|
||||
* When running this example on a multitasking system, we must
|
||||
* give other processes a chance to run too and therefore we call
|
||||
* usleep() resp. Sleep() here. On a dedicated embedded system,
|
||||
* we usually do not need to do this.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
Sleep(0);
|
||||
#else
|
||||
usleep(10);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Finally, the implementation of the simple timer library follows.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
|
||||
static int clock_time(void)
|
||||
{ return (int)GetTickCount(); }
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
static int clock_time(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
gettimeofday(&tv, &tz);
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
static int timer_expired(struct timer *t)
|
||||
{ return (int)(clock_time() - t->start) >= (int)t->interval; }
|
||||
|
||||
static void timer_set(struct timer *t, int interval)
|
||||
{ t->interval = interval; t->start = clock_time(); }
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* This is a very small example that shows how to use
|
||||
* protothreads. The program consists of two protothreads that wait
|
||||
* for each other to toggle a variable.
|
||||
*/
|
||||
|
||||
/* We must always include pt.h in our protothreads code. */
|
||||
#include "pt.h"
|
||||
|
||||
#include <stdio.h> /* For printf(). */
|
||||
|
||||
/* Two flags that the two protothread functions use. */
|
||||
static int protothread1_flag, protothread2_flag;
|
||||
|
||||
/**
|
||||
* The first protothread function. A protothread function must always
|
||||
* return an integer, but must never explicitly return - returning is
|
||||
* performed inside the protothread statements.
|
||||
*
|
||||
* The protothread function is driven by the main loop further down in
|
||||
* the code.
|
||||
*/
|
||||
static int
|
||||
protothread1(struct pt *pt)
|
||||
{
|
||||
/* A protothread function must begin with PT_BEGIN() which takes a
|
||||
pointer to a struct pt. */
|
||||
PT_BEGIN(pt);
|
||||
|
||||
/* We loop forever here. */
|
||||
while(1) {
|
||||
/* Wait until the other protothread has set its flag. */
|
||||
PT_WAIT_UNTIL(pt, protothread2_flag != 0);
|
||||
printf("Protothread 1 running\n");
|
||||
|
||||
/* We then reset the other protothread's flag, and set our own
|
||||
flag so that the other protothread can run. */
|
||||
protothread2_flag = 0;
|
||||
protothread1_flag = 1;
|
||||
|
||||
/* And we loop. */
|
||||
}
|
||||
|
||||
/* All protothread functions must end with PT_END() which takes a
|
||||
pointer to a struct pt. */
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* The second protothread function. This is almost the same as the
|
||||
* first one.
|
||||
*/
|
||||
static int
|
||||
protothread2(struct pt *pt)
|
||||
{
|
||||
PT_BEGIN(pt);
|
||||
|
||||
while(1) {
|
||||
/* Let the other protothread run. */
|
||||
protothread2_flag = 1;
|
||||
|
||||
/* Wait until the other protothread has set its flag. */
|
||||
PT_WAIT_UNTIL(pt, protothread1_flag != 0);
|
||||
printf("Protothread 2 running\n");
|
||||
|
||||
/* We then reset the other protothread's flag. */
|
||||
protothread1_flag = 0;
|
||||
|
||||
/* And we loop. */
|
||||
}
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally, we have the main loop. Here is where the protothreads are
|
||||
* initialized and scheduled. First, however, we define the
|
||||
* protothread state variables pt1 and pt2, which hold the state of
|
||||
* the two protothreads.
|
||||
*/
|
||||
static struct pt pt1, pt2;
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Initialize the protothread state variables with PT_INIT(). */
|
||||
PT_INIT(&pt1);
|
||||
PT_INIT(&pt2);
|
||||
|
||||
/*
|
||||
* Then we schedule the two protothreads by repeatedly calling their
|
||||
* protothread functions and passing a pointer to the protothread
|
||||
* state variables as arguments.
|
||||
*/
|
||||
while(1) {
|
||||
protothread1(&pt1);
|
||||
protothread2(&pt2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: lc-addrlabels.h,v 1.4 2006/06/03 11:29:43 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup lc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of local continuations based on the "Labels as
|
||||
* values" feature of gcc
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* This implementation of local continuations is based on a special
|
||||
* feature of the GCC C compiler called "labels as values". This
|
||||
* feature allows assigning pointers with the address of the code
|
||||
* corresponding to a particular C label.
|
||||
*
|
||||
* For more information, see the GCC documentation:
|
||||
* http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LC_ADDRLABELS_H__
|
||||
#define __LC_ADDRLABELS_H__
|
||||
|
||||
/** \hideinitializer */
|
||||
typedef void * lc_t;
|
||||
|
||||
#define LC_INIT(s) s = NULL
|
||||
|
||||
#define LC_RESUME(s) \
|
||||
do { \
|
||||
if(s != NULL) { \
|
||||
goto *s; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define LC_CONCAT2(s1, s2) s1##s2
|
||||
#define LC_CONCAT(s1, s2) LC_CONCAT2(s1, s2)
|
||||
|
||||
#define LC_SET(s) \
|
||||
do { \
|
||||
LC_CONCAT(LC_LABEL, __LINE__): \
|
||||
(s) = &&LC_CONCAT(LC_LABEL, __LINE__); \
|
||||
} while(0)
|
||||
|
||||
#define LC_END(s)
|
||||
|
||||
#endif /* __LC_ADDRLABELS_H__ */
|
||||
/** @} */
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: lc-switch.h,v 1.4 2006/06/03 11:29:43 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup lc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Implementation of local continuations based on switch() statment
|
||||
* \author Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* This implementation of local continuations uses the C switch()
|
||||
* statement to resume execution of a function somewhere inside the
|
||||
* function's body. The implementation is based on the fact that
|
||||
* switch() statements are able to jump directly into the bodies of
|
||||
* control structures such as if() or while() statmenets.
|
||||
*
|
||||
* This implementation borrows heavily from Simon Tatham's coroutines
|
||||
* implementation in C:
|
||||
* http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
*/
|
||||
|
||||
#ifndef __LC_SWITCH_H__
|
||||
#define __LC_SWITCH_H__
|
||||
|
||||
/* WARNING! lc implementation using switch() does not work if an
|
||||
LC_SET() is done within another switch() statement! */
|
||||
|
||||
/** \hideinitializer */
|
||||
typedef unsigned short lc_t;
|
||||
|
||||
#define LC_INIT(s) s = 0;
|
||||
|
||||
#define LC_RESUME(s) switch(s) { case 0:
|
||||
|
||||
#define LC_SET(s) s = __LINE__; case __LINE__:
|
||||
|
||||
#define LC_END(s) }
|
||||
|
||||
#endif /* __LC_SWITCH_H__ */
|
||||
|
||||
/** @} */
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the protothreads library.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: lc.h,v 1.2 2005/02/24 10:36:59 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup pt
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup lc Local continuations
|
||||
* @{
|
||||
*
|
||||
* Local continuations form the basis for implementing protothreads. A
|
||||
* local continuation can be <i>set</i> in a specific function to
|
||||
* capture the state of the function. After a local continuation has
|
||||
* been set can be <i>resumed</i> in order to restore the state of the
|
||||
* function at the point where the local continuation was set.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file lc.h
|
||||
* Local continuations
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* Initialize a local continuation.
|
||||
*
|
||||
* This operation initializes the local continuation, thereby
|
||||
* unsetting any previously set continuation state.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define LC_INIT(lc)
|
||||
|
||||
/**
|
||||
* Set a local continuation.
|
||||
*
|
||||
* The set operation saves the state of the function at the point
|
||||
* where the operation is executed. As far as the set operation is
|
||||
* concerned, the state of the function does <b>not</b> include the
|
||||
* call-stack or local (automatic) variables, but only the program
|
||||
* counter and such CPU registers that needs to be saved.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define LC_SET(lc)
|
||||
|
||||
/**
|
||||
* Resume a local continuation.
|
||||
*
|
||||
* The resume operation resumes a previously set local continuation, thus
|
||||
* restoring the state in which the function was when the local
|
||||
* continuation was set. If the local continuation has not been
|
||||
* previously set, the resume operation does nothing.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define LC_RESUME(lc)
|
||||
|
||||
/**
|
||||
* Mark the end of local continuation usage.
|
||||
*
|
||||
* The end operation signifies that local continuations should not be
|
||||
* used any more in the function. This operation is not needed for
|
||||
* most implementations of local continuation, but is required by a
|
||||
* few implementations.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define LC_END(lc)
|
||||
|
||||
/**
|
||||
* \var typedef lc_t;
|
||||
*
|
||||
* The local continuation type.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#endif /* DOXYGEN */
|
||||
|
||||
#ifndef __LC_H__
|
||||
#define __LC_H__
|
||||
|
||||
|
||||
#ifdef LC_INCLUDE
|
||||
#include LC_INCLUDE
|
||||
#else
|
||||
#include "lc-switch.h"
|
||||
#endif /* LC_INCLUDE */
|
||||
|
||||
#endif /* __LC_H__ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the protothreads library.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: pt-sem.h,v 1.2 2005/02/24 10:36:59 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup pt
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup ptsem Protothread semaphores
|
||||
* @{
|
||||
*
|
||||
* This module implements counting semaphores on top of
|
||||
* protothreads. Semaphores are a synchronization primitive that
|
||||
* provide two operations: "wait" and "signal". The "wait" operation
|
||||
* checks the semaphore counter and blocks the thread if the counter
|
||||
* is zero. The "signal" operation increases the semaphore counter but
|
||||
* does not block. If another thread has blocked waiting for the
|
||||
* semaphore that is signalled, the blocked thread will become
|
||||
* runnable again.
|
||||
*
|
||||
* Semaphores can be used to implement other, more structured,
|
||||
* synchronization primitives such as monitors and message
|
||||
* queues/bounded buffers (see below).
|
||||
*
|
||||
* The following example shows how the producer-consumer problem, also
|
||||
* known as the bounded buffer problem, can be solved using
|
||||
* protothreads and semaphores. Notes on the program follow after the
|
||||
* example.
|
||||
*
|
||||
\code
|
||||
#include "pt-sem.h"
|
||||
|
||||
#define NUM_ITEMS 32
|
||||
#define BUFSIZE 8
|
||||
|
||||
static struct pt_sem mutex, full, empty;
|
||||
|
||||
PT_THREAD(producer(struct pt *pt))
|
||||
{
|
||||
static int produced;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
for(produced = 0; produced < NUM_ITEMS; ++produced) {
|
||||
|
||||
PT_SEM_WAIT(pt, &full);
|
||||
|
||||
PT_SEM_WAIT(pt, &mutex);
|
||||
add_to_buffer(produce_item());
|
||||
PT_SEM_SIGNAL(pt, &mutex);
|
||||
|
||||
PT_SEM_SIGNAL(pt, &empty);
|
||||
}
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
PT_THREAD(consumer(struct pt *pt))
|
||||
{
|
||||
static int consumed;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
for(consumed = 0; consumed < NUM_ITEMS; ++consumed) {
|
||||
|
||||
PT_SEM_WAIT(pt, &empty);
|
||||
|
||||
PT_SEM_WAIT(pt, &mutex);
|
||||
consume_item(get_from_buffer());
|
||||
PT_SEM_SIGNAL(pt, &mutex);
|
||||
|
||||
PT_SEM_SIGNAL(pt, &full);
|
||||
}
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
|
||||
PT_THREAD(driver_thread(struct pt *pt))
|
||||
{
|
||||
static struct pt pt_producer, pt_consumer;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
PT_SEM_INIT(&empty, 0);
|
||||
PT_SEM_INIT(&full, BUFSIZE);
|
||||
PT_SEM_INIT(&mutex, 1);
|
||||
|
||||
PT_INIT(&pt_producer);
|
||||
PT_INIT(&pt_consumer);
|
||||
|
||||
PT_WAIT_THREAD(pt, producer(&pt_producer) &
|
||||
consumer(&pt_consumer));
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
\endcode
|
||||
*
|
||||
* The program uses three protothreads: one protothread that
|
||||
* implements the consumer, one thread that implements the producer,
|
||||
* and one protothread that drives the two other protothreads. The
|
||||
* program uses three semaphores: "full", "empty" and "mutex". The
|
||||
* "mutex" semaphore is used to provide mutual exclusion for the
|
||||
* buffer, the "empty" semaphore is used to block the consumer is the
|
||||
* buffer is empty, and the "full" semaphore is used to block the
|
||||
* producer is the buffer is full.
|
||||
*
|
||||
* The "driver_thread" holds two protothread state variables,
|
||||
* "pt_producer" and "pt_consumer". It is important to note that both
|
||||
* these variables are declared as <i>static</i>. If the static
|
||||
* keyword is not used, both variables are stored on the stack. Since
|
||||
* protothreads do not store the stack, these variables may be
|
||||
* overwritten during a protothread wait operation. Similarly, both
|
||||
* the "consumer" and "producer" protothreads declare their local
|
||||
* variables as static, to avoid them being stored on the stack.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Couting semaphores implemented on protothreads
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PT_SEM_H__
|
||||
#define __PT_SEM_H__
|
||||
|
||||
#include "pt.h"
|
||||
|
||||
struct pt_sem {
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a semaphore
|
||||
*
|
||||
* This macro initializes a semaphore with a value for the
|
||||
* counter. Internally, the semaphores use an "unsigned int" to
|
||||
* represent the counter, and therefore the "count" argument should be
|
||||
* within range of an unsigned int.
|
||||
*
|
||||
* \param s (struct pt_sem *) A pointer to the pt_sem struct
|
||||
* representing the semaphore
|
||||
*
|
||||
* \param c (unsigned int) The initial count of the semaphore.
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_SEM_INIT(s, c) (s)->count = c
|
||||
|
||||
/**
|
||||
* Wait for a semaphore
|
||||
*
|
||||
* This macro carries out the "wait" operation on the semaphore. The
|
||||
* wait operation causes the protothread to block while the counter is
|
||||
* zero. When the counter reaches a value larger than zero, the
|
||||
* protothread will continue.
|
||||
*
|
||||
* \param pt (struct pt *) A pointer to the protothread (struct pt) in
|
||||
* which the operation is executed.
|
||||
*
|
||||
* \param s (struct pt_sem *) A pointer to the pt_sem struct
|
||||
* representing the semaphore
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_SEM_WAIT(pt, s) \
|
||||
do { \
|
||||
PT_WAIT_UNTIL(pt, (s)->count > 0); \
|
||||
--(s)->count; \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Signal a semaphore
|
||||
*
|
||||
* This macro carries out the "signal" operation on the semaphore. The
|
||||
* signal operation increments the counter inside the semaphore, which
|
||||
* eventually will cause waiting protothreads to continue executing.
|
||||
*
|
||||
* \param pt (struct pt *) A pointer to the protothread (struct pt) in
|
||||
* which the operation is executed.
|
||||
*
|
||||
* \param s (struct pt_sem *) A pointer to the pt_sem struct
|
||||
* representing the semaphore
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_SEM_SIGNAL(pt, s) ++(s)->count
|
||||
|
||||
#endif /* __PT_SEM_H__ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
|
@ -0,0 +1,315 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2005, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: pt.h,v 1.7 2006/10/02 07:52:56 adam Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup pt
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Protothreads implementation.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PT_H__
|
||||
#define __PT_H__
|
||||
|
||||
#include "lc.h"
|
||||
|
||||
struct pt {
|
||||
lc_t lc;
|
||||
};
|
||||
|
||||
#define PT_WAITING 0
|
||||
#define PT_YIELDED 1
|
||||
#define PT_EXITED 2
|
||||
#define PT_ENDED 3
|
||||
|
||||
/**
|
||||
* \name 初始化
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 初始化protothread线程
|
||||
*
|
||||
* 初始化protothread线程。初始化必须在开始执行原型线程之前完成。
|
||||
*
|
||||
* \param pt 指向protothread线程控制结构的指针
|
||||
*
|
||||
* \sa PT_SPAWN()
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_INIT(pt) LC_INIT((pt)->lc)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name 声明和定义
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 声明protothread线程。
|
||||
*
|
||||
* 此宏用于声明protothread线程。必须使用此宏声明所有protothread线程
|
||||
*
|
||||
* \param name_args 实现protothread线程的 C 函数的名称和参数。
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_THREAD(name_args) char name_args
|
||||
|
||||
/**
|
||||
* 在实现protothread线程的 C 函数中声明protothread线程的开始
|
||||
*
|
||||
* 此宏用于声明protothread线程的起点。它应该放在运行protothread线程的函数的开头。
|
||||
* 每次调度 protothread 时,都将执行 PT_BEGIN() 调用上方的所有 C 语句。
|
||||
*
|
||||
* \param pt 指向原型线程控制结构的指针。
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc)
|
||||
|
||||
/**
|
||||
* 声明原型线程的结束。
|
||||
*
|
||||
* 此宏用于声明原型线程结束。它必须始终与匹配的 PT_BEGIN() 宏一起使用。
|
||||
*
|
||||
* \param pt 指向原型线程控制结构的指针。
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \
|
||||
PT_INIT(pt); return PT_ENDED; }
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name 阻止等待
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 阻止并等待条件为真
|
||||
*
|
||||
* 此宏会阻塞原型线程,直到指定的条件为真
|
||||
*
|
||||
* \param pt 指向原型线程控制结构的指针
|
||||
* \param condition 条件。
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_WAIT_UNTIL(pt, condition) \
|
||||
do { \
|
||||
LC_SET((pt)->lc); \
|
||||
if(!(condition)) { \
|
||||
return PT_WAITING; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* 阻止并等待条件为真。
|
||||
*
|
||||
* 此功能在条件为真时阻止并等待. See
|
||||
* PT_WAIT_UNTIL().
|
||||
*
|
||||
* \param pt 指向原型线程控制结构的指针
|
||||
* \param cond 条件。
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name 分层原型线程
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 阻止并等待子原型线程完成。
|
||||
*
|
||||
* This macro schedules a child protothread. The current protothread
|
||||
* will block until the child protothread completes.
|
||||
*
|
||||
* \note The child protothread must be manually initialized with the
|
||||
* PT_INIT() function before this function is used.
|
||||
*
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
* \param thread The child protothread with arguments
|
||||
*
|
||||
* \sa PT_SPAWN()
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))
|
||||
|
||||
/**
|
||||
* Spawn a child protothread and wait until it exits.
|
||||
*
|
||||
* This macro spawns a child protothread and waits until it exits. The
|
||||
* macro can only be used within a protothread.
|
||||
*
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
* \param child A pointer to the child protothread's control structure.
|
||||
* \param thread The child protothread with arguments
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_SPAWN(pt, child, thread) \
|
||||
do { \
|
||||
PT_INIT((child)); \
|
||||
PT_WAIT_THREAD((pt), (thread)); \
|
||||
} while(0)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name Exiting and restarting
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Restart the protothread.
|
||||
*
|
||||
* This macro will block and cause the running protothread to restart
|
||||
* its execution at the place of the PT_BEGIN() call.
|
||||
*
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_RESTART(pt) \
|
||||
do { \
|
||||
PT_INIT(pt); \
|
||||
return PT_WAITING; \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Exit the protothread.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_EXIT(pt) \
|
||||
do { \
|
||||
PT_INIT(pt); \
|
||||
return PT_EXITED; \
|
||||
} while(0)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name Calling a protothread
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Schedule a protothread.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \param f The call to the C function implementing the protothread to
|
||||
* be scheduled
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_SCHEDULE(f) ((f) < PT_EXITED)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name Yielding from a protothread
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Yield from the current protothread.
|
||||
*
|
||||
* This function will yield the protothread, thereby allowing other
|
||||
* processing to take place in the system.
|
||||
*
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_YIELD(pt) \
|
||||
do { \
|
||||
PT_YIELD_FLAG = 0; \
|
||||
LC_SET((pt)->lc); \
|
||||
if(PT_YIELD_FLAG == 0) { \
|
||||
return PT_YIELDED; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* \brief Yield from the protothread until a condition occurs.
|
||||
* \param pt A pointer to the protothread control structure.
|
||||
* \param cond The condition.
|
||||
*
|
||||
* This function will yield the protothread, until the
|
||||
* specified condition evaluates to true.
|
||||
*
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define PT_YIELD_UNTIL(pt, cond) \
|
||||
do { \
|
||||
PT_YIELD_FLAG = 0; \
|
||||
LC_SET((pt)->lc); \
|
||||
if((PT_YIELD_FLAG == 0) || !(cond)) { \
|
||||
return PT_YIELDED; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* __PT_H__ */
|
||||
|
||||
/** @} */
|