├── Makefile ├── README ├── doc ├── Doxyfile ├── Makefile ├── header.tex ├── html │ ├── a00003.html │ ├── a00004.html │ ├── a00005.html │ ├── a00006.html │ ├── a00007.html │ ├── a00008.html │ ├── a00009.html │ ├── a00010.html │ ├── a00010.png │ ├── a00011.html │ ├── a00012.html │ ├── a00012.png │ ├── a00013.html │ ├── a00013.png │ ├── a00014.html │ ├── a00014.png │ ├── a00015.html │ ├── a00015.png │ ├── a00016.html │ ├── a00016.map │ ├── a00016.md5 │ ├── a00016.png │ ├── a00017.html │ ├── a00018.html │ ├── a00018.map │ ├── a00018.md5 │ ├── a00018.png │ ├── a00019.html │ ├── a00020.html │ ├── a00020.map │ ├── a00020.md5 │ ├── a00020.png │ ├── a00021.html │ ├── a00022.html │ ├── a00022.map │ ├── a00022.md5 │ ├── a00022.png │ ├── a00023.map │ ├── a00023.md5 │ ├── a00023.png │ ├── a00024.map │ ├── a00024.md5 │ ├── a00024.png │ ├── a00025.map │ ├── a00025.md5 │ ├── a00025.png │ ├── a00026.map │ ├── a00026.md5 │ ├── a00026.png │ ├── a00027.map │ ├── a00027.md5 │ ├── a00027.png │ ├── a00028.map │ ├── a00028.md5 │ ├── a00028.png │ ├── a00029.map │ ├── a00029.md5 │ ├── a00029.png │ ├── a00040.map │ ├── a00040.md5 │ ├── a00040.png │ ├── a00042.map │ ├── a00042.md5 │ ├── a00042.png │ ├── annotated.html │ ├── doxygen.css │ ├── doxygen.png │ ├── examples.html │ ├── files.html │ ├── ftv2blank.png │ ├── ftv2doc.png │ ├── ftv2folderclosed.png │ ├── ftv2folderopen.png │ ├── ftv2lastnode.png │ ├── ftv2link.png │ ├── ftv2mlastnode.png │ ├── ftv2mnode.png │ ├── ftv2node.png │ ├── ftv2plastnode.png │ ├── ftv2pnode.png │ ├── ftv2vertline.png │ ├── functions.html │ ├── functions_vars.html │ ├── globals.html │ ├── globals_defs.html │ ├── globals_type.html │ ├── graph_legend.dot │ ├── graph_legend.html │ ├── graph_legend.png │ ├── hierarchy.html │ ├── index.hhc │ ├── index.hhk │ ├── index.hhp │ ├── index.html │ ├── inherits.html │ ├── main.html │ ├── modules.html │ ├── pages.html │ ├── tab_b.gif │ ├── tab_l.gif │ ├── tab_r.gif │ ├── tabs.css │ ├── tree.html │ └── using.html ├── pt-doc.txt ├── pt-mainpage.txt ├── pt-refman.pdf └── sicslogo.pdf ├── example-buffer.c ├── example-codelock.c ├── example-small.c ├── graham-pt.h ├── lc-addrlabels.h ├── lc-switch.h ├── lc.h ├── pt-sem.h └── pt.h /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-O -Wuninitialized -Werror 2 | 3 | all: example-codelock example-buffer example-small 4 | 5 | clean: 6 | rm example-codelock example-buffer example-small 7 | 8 | example-codelock: example-codelock.c pt.h lc.h 9 | 10 | example-buffer: example-buffer.c pt.h lc.h 11 | 12 | example-small: example-small.c pt.h lc.h 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Protothreads are extremely lightweight stackless threads designed for 2 | severely memory constrained systems such as small embedded systems or 3 | sensor network nodes. Protothreads can be used with or without an 4 | underlying operating system. 5 | 6 | Protothreads provides a blocking context on top of an event-driven 7 | system, without the overhead of per-thread stacks. The purpose of 8 | protothreads is to implement sequential flow of control without 9 | complex state machines or full multi-threading. 10 | 11 | Main features: 12 | 13 | * No machine specific code - the protothreads library is pure C 14 | * Does not use error-prone functions such as longjmp() 15 | * Very small RAM overhead - only two bytes per protothread 16 | * Can be used with or without an OS 17 | * Provides blocking wait without full multi-threading or 18 | stack-switching 19 | * Freely available under a BSD-like open source license 20 | 21 | Example applications: 22 | 23 | * Memory constrained systems 24 | * Event-driven protocol stacks 25 | * Small embedded systems 26 | * Sensor network nodes 27 | 28 | The protothreads library is released under an open source BSD-style 29 | license that allows for both non-commercial and commercial usage. The 30 | only requirement is that credit is given. 31 | 32 | The protothreads library was written by Adam Dunkels 33 | with support from Oliver Schmidt . 34 | 35 | More information and new versions can be found at the protothreads 36 | homepage: 37 | http://dunkels.com/adam/pt/ 38 | (was: http://www.sics.se/~adam/pt/ 39 | http://web.archive.org/web/20110610191935/http://www.sics.se/~adam/pt/index.html) 40 | 41 | 42 | Documentation can be found in the doc/ subdirectory. 43 | 44 | Two example programs illustrating the use of protothreads can be found 45 | in this directory: 46 | 47 | example-small.c A small example showing how to use protothreads 48 | example-buffer.c The bounded buffer problem with protothreads 49 | example-codelock.c A code lock with simulated key input 50 | 51 | To compile the examples, simply run "make". 52 | 53 | 54 | Adam Dunkels, 3 June 2006 55 | -------------------------------------------------------------------------------- /doc/Doxyfile: -------------------------------------------------------------------------------- 1 | # Doxyfile 1.4.6 2 | 3 | #--------------------------------------------------------------------------- 4 | # Project related configuration options 5 | #--------------------------------------------------------------------------- 6 | PROJECT_NAME = "The Protothreads Library 1.3" 7 | PROJECT_NUMBER = 8 | OUTPUT_DIRECTORY = . 9 | CREATE_SUBDIRS = NO 10 | OUTPUT_LANGUAGE = English 11 | USE_WINDOWS_ENCODING = NO 12 | BRIEF_MEMBER_DESC = YES 13 | REPEAT_BRIEF = YES 14 | ABBREVIATE_BRIEF = 15 | ALWAYS_DETAILED_SEC = NO 16 | INLINE_INHERITED_MEMB = NO 17 | FULL_PATH_NAMES = YES 18 | STRIP_FROM_PATH = ../ 19 | STRIP_FROM_INC_PATH = 20 | SHORT_NAMES = YES 21 | JAVADOC_AUTOBRIEF = YES 22 | MULTILINE_CPP_IS_BRIEF = NO 23 | DETAILS_AT_TOP = YES 24 | INHERIT_DOCS = YES 25 | SEPARATE_MEMBER_PAGES = NO 26 | TAB_SIZE = 8 27 | ALIASES = 28 | OPTIMIZE_OUTPUT_FOR_C = YES 29 | OPTIMIZE_OUTPUT_JAVA = NO 30 | BUILTIN_STL_SUPPORT = NO 31 | DISTRIBUTE_GROUP_DOC = NO 32 | SUBGROUPING = YES 33 | #--------------------------------------------------------------------------- 34 | # Build related configuration options 35 | #--------------------------------------------------------------------------- 36 | EXTRACT_ALL = NO 37 | EXTRACT_PRIVATE = NO 38 | EXTRACT_STATIC = NO 39 | EXTRACT_LOCAL_CLASSES = NO 40 | EXTRACT_LOCAL_METHODS = NO 41 | HIDE_UNDOC_MEMBERS = YES 42 | HIDE_UNDOC_CLASSES = YES 43 | HIDE_FRIEND_COMPOUNDS = NO 44 | HIDE_IN_BODY_DOCS = NO 45 | INTERNAL_DOCS = NO 46 | CASE_SENSE_NAMES = YES 47 | HIDE_SCOPE_NAMES = NO 48 | SHOW_INCLUDE_FILES = YES 49 | INLINE_INFO = YES 50 | SORT_MEMBER_DOCS = YES 51 | SORT_BRIEF_DOCS = NO 52 | SORT_BY_SCOPE_NAME = NO 53 | GENERATE_TODOLIST = YES 54 | GENERATE_TESTLIST = YES 55 | GENERATE_BUGLIST = NO 56 | GENERATE_DEPRECATEDLIST= NO 57 | ENABLED_SECTIONS = 58 | MAX_INITIALIZER_LINES = 30 59 | SHOW_USED_FILES = NO 60 | SHOW_DIRECTORIES = NO 61 | FILE_VERSION_FILTER = 62 | #--------------------------------------------------------------------------- 63 | # configuration options related to warning and progress messages 64 | #--------------------------------------------------------------------------- 65 | QUIET = NO 66 | WARNINGS = YES 67 | WARN_IF_UNDOCUMENTED = YES 68 | WARN_IF_DOC_ERROR = YES 69 | WARN_NO_PARAMDOC = NO 70 | WARN_FORMAT = "$file:$line: $text" 71 | WARN_LOGFILE = 72 | #--------------------------------------------------------------------------- 73 | # configuration options related to the input files 74 | #--------------------------------------------------------------------------- 75 | INPUT = pt-mainpage.txt \ 76 | pt-doc.txt \ 77 | ../pt.h \ 78 | ../pt-sem.h \ 79 | ../lc.h \ 80 | ../lc-switch.h \ 81 | ../lc-addrlabels.h 82 | FILE_PATTERNS = 83 | RECURSIVE = NO 84 | EXCLUDE = 85 | EXCLUDE_SYMLINKS = NO 86 | EXCLUDE_PATTERNS = 87 | EXAMPLE_PATH = .. 88 | EXAMPLE_PATTERNS = 89 | EXAMPLE_RECURSIVE = NO 90 | IMAGE_PATH = 91 | INPUT_FILTER = 92 | FILTER_PATTERNS = 93 | FILTER_SOURCE_FILES = NO 94 | #--------------------------------------------------------------------------- 95 | # configuration options related to source browsing 96 | #--------------------------------------------------------------------------- 97 | SOURCE_BROWSER = YES 98 | INLINE_SOURCES = YES 99 | STRIP_CODE_COMMENTS = NO 100 | REFERENCED_BY_RELATION = YES 101 | REFERENCES_RELATION = YES 102 | USE_HTAGS = NO 103 | VERBATIM_HEADERS = YES 104 | #--------------------------------------------------------------------------- 105 | # configuration options related to the alphabetical class index 106 | #--------------------------------------------------------------------------- 107 | ALPHABETICAL_INDEX = NO 108 | COLS_IN_ALPHA_INDEX = 5 109 | IGNORE_PREFIX = 110 | #--------------------------------------------------------------------------- 111 | # configuration options related to the HTML output 112 | #--------------------------------------------------------------------------- 113 | GENERATE_HTML = YES 114 | HTML_OUTPUT = html 115 | HTML_FILE_EXTENSION = .html 116 | HTML_HEADER = 117 | HTML_FOOTER = 118 | HTML_STYLESHEET = 119 | HTML_ALIGN_MEMBERS = YES 120 | GENERATE_HTMLHELP = YES 121 | CHM_FILE = 122 | HHC_LOCATION = 123 | GENERATE_CHI = NO 124 | BINARY_TOC = NO 125 | TOC_EXPAND = NO 126 | DISABLE_INDEX = NO 127 | ENUM_VALUES_PER_LINE = 4 128 | GENERATE_TREEVIEW = YES 129 | TREEVIEW_WIDTH = 250 130 | #--------------------------------------------------------------------------- 131 | # configuration options related to the LaTeX output 132 | #--------------------------------------------------------------------------- 133 | GENERATE_LATEX = YES 134 | LATEX_OUTPUT = latex 135 | LATEX_CMD_NAME = latex 136 | MAKEINDEX_CMD_NAME = makeindex 137 | COMPACT_LATEX = YES 138 | PAPER_TYPE = a4 139 | EXTRA_PACKAGES = 140 | LATEX_HEADER = header.tex 141 | PDF_HYPERLINKS = YES 142 | USE_PDFLATEX = YES 143 | LATEX_BATCHMODE = NO 144 | LATEX_HIDE_INDICES = NO 145 | #--------------------------------------------------------------------------- 146 | # configuration options related to the RTF output 147 | #--------------------------------------------------------------------------- 148 | GENERATE_RTF = NO 149 | RTF_OUTPUT = rtf 150 | COMPACT_RTF = NO 151 | RTF_HYPERLINKS = NO 152 | RTF_STYLESHEET_FILE = 153 | RTF_EXTENSIONS_FILE = 154 | #--------------------------------------------------------------------------- 155 | # configuration options related to the man page output 156 | #--------------------------------------------------------------------------- 157 | GENERATE_MAN = NO 158 | MAN_OUTPUT = man 159 | MAN_EXTENSION = .3 160 | MAN_LINKS = NO 161 | #--------------------------------------------------------------------------- 162 | # configuration options related to the XML output 163 | #--------------------------------------------------------------------------- 164 | GENERATE_XML = NO 165 | XML_OUTPUT = xml 166 | XML_SCHEMA = 167 | XML_DTD = 168 | XML_PROGRAMLISTING = YES 169 | #--------------------------------------------------------------------------- 170 | # configuration options for the AutoGen Definitions output 171 | #--------------------------------------------------------------------------- 172 | GENERATE_AUTOGEN_DEF = NO 173 | #--------------------------------------------------------------------------- 174 | # configuration options related to the Perl module output 175 | #--------------------------------------------------------------------------- 176 | GENERATE_PERLMOD = NO 177 | PERLMOD_LATEX = NO 178 | PERLMOD_PRETTY = YES 179 | PERLMOD_MAKEVAR_PREFIX = 180 | #--------------------------------------------------------------------------- 181 | # Configuration options related to the preprocessor 182 | #--------------------------------------------------------------------------- 183 | ENABLE_PREPROCESSING = YES 184 | MACRO_EXPANSION = NO 185 | EXPAND_ONLY_PREDEF = NO 186 | SEARCH_INCLUDES = YES 187 | INCLUDE_PATH = 188 | INCLUDE_FILE_PATTERNS = 189 | PREDEFINED = DOXYGEN 190 | EXPAND_AS_DEFINED = 191 | SKIP_FUNCTION_MACROS = YES 192 | #--------------------------------------------------------------------------- 193 | # Configuration::additions related to external references 194 | #--------------------------------------------------------------------------- 195 | TAGFILES = 196 | GENERATE_TAGFILE = 197 | ALLEXTERNALS = NO 198 | EXTERNAL_GROUPS = YES 199 | PERL_PATH = /usr/bin/perl 200 | #--------------------------------------------------------------------------- 201 | # Configuration options related to the dot tool 202 | #--------------------------------------------------------------------------- 203 | CLASS_DIAGRAMS = YES 204 | HIDE_UNDOC_RELATIONS = YES 205 | HAVE_DOT = YES 206 | CLASS_GRAPH = NO 207 | COLLABORATION_GRAPH = YES 208 | GROUP_GRAPHS = YES 209 | UML_LOOK = NO 210 | TEMPLATE_RELATIONS = NO 211 | INCLUDE_GRAPH = NO 212 | INCLUDED_BY_GRAPH = YES 213 | CALL_GRAPH = YES 214 | GRAPHICAL_HIERARCHY = YES 215 | DIRECTORY_GRAPH = YES 216 | DOT_IMAGE_FORMAT = png 217 | DOT_PATH = 218 | DOTFILE_DIRS = 219 | MAX_DOT_GRAPH_WIDTH = 1024 220 | MAX_DOT_GRAPH_HEIGHT = 1024 221 | MAX_DOT_GRAPH_DEPTH = 0 222 | DOT_TRANSPARENT = NO 223 | DOT_MULTI_TARGETS = NO 224 | GENERATE_LEGEND = YES 225 | DOT_CLEANUP = YES 226 | #--------------------------------------------------------------------------- 227 | # Configuration::additions related to the search engine 228 | #--------------------------------------------------------------------------- 229 | SEARCHENGINE = NO 230 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | dox: 2 | doxygen Doxyfile 3 | 4 | 5 | pdf: dox 6 | (cd latex; $(MAKE) refman.pdf) 7 | mv latex/refman.pdf pt-refman.pdf -------------------------------------------------------------------------------- /doc/header.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper]{article} 2 | \usepackage{a4wide} 3 | \usepackage{makeidx} 4 | \usepackage{fancyhdr} 5 | \usepackage{graphicx} 6 | \usepackage{multicol} 7 | \usepackage{float} 8 | \usepackage{textcomp} 9 | \usepackage{alltt} 10 | \usepackage{times} 11 | \usepackage{epsfig} 12 | \ifx\pdfoutput\undefined 13 | \usepackage[ps2pdf, 14 | pagebackref=true, 15 | colorlinks=true, 16 | linkcolor=blue 17 | ]{hyperref} 18 | \usepackage{pspicture} 19 | \else 20 | \usepackage[pdftex, 21 | pagebackref=true, 22 | colorlinks=true, 23 | linkcolor=blue 24 | ]{hyperref} 25 | \fi 26 | \usepackage{doxygen} 27 | \makeindex 28 | \setcounter{tocdepth}{1} 29 | \renewcommand{\footrulewidth}{0.4pt} 30 | \begin{document} 31 | \begin{titlepage} 32 | \vspace*{5cm} 33 | \begin{center} 34 | {\Huge Protothreads}\\ 35 | \vspace*{1cm} 36 | {\LARGE The Protothreads Library 1.1 Reference Manual}\\ 37 | \vspace*{3cm} 38 | {\Large April 2005}\\ 39 | \vspace*{2cm} 40 | \includegraphics[width=6cm]{../sicslogo.pdf}\\ 41 | \vspace*{1cm} 42 | {\Large Adam Dunkels}\\ 43 | {\Large \texttt{adam@sics.se}}\\ 44 | \vspace*{1cm} 45 | {\LARGE Swedish Institute of Computer Science}\\ 46 | \vspace*{0.5cm} 47 | 48 | \end{center} 49 | \end{titlepage} 50 | \pagenumbering{roman} 51 | \tableofcontents 52 | \pagenumbering{arabic} 53 | -------------------------------------------------------------------------------- /doc/html/a00003.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt Struct Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

pt Struct Reference
22 | 23 | [Protothreads] 24 |


Detailed Description

25 | 26 |

27 | 28 |

29 | Definition at line 52 of file pt.h. 30 | 31 | 32 | 34 | 35 |

Data Fields

33 | lc_t lc
36 |


Generated on Sat Jun 3 13:53:31 2006 for The Protothreads Library 1.3 by  37 | 38 | doxygen 1.4.6
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/html/a00004.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt_sem Struct Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

pt_sem Struct Reference
22 | 23 | [Protothread semaphores] 24 |


Detailed Description

25 | 26 |

27 | 28 |

29 | Definition at line 165 of file pt-sem.h. 30 | 31 | 32 | 34 | 35 |

Data Fields

33 | unsigned int count
36 |


Generated on Sat Jun 3 13:53:31 2006 for The Protothreads Library 1.3 by  37 | 38 | doxygen 1.4.6
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/html/a00005.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt Struct Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

pt Struct Reference
22 | 23 | [Protothreads] 24 |


Detailed Description

25 | 26 |

27 | 28 |

29 | Definition at line 52 of file pt.h. 30 | 31 | 32 | 34 | 35 |

Data Fields

33 | lc_t lc
36 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  37 | 38 | doxygen 1.4.6
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/html/a00006.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt_sem Struct Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

pt_sem Struct Reference
22 | 23 | [Protothread semaphores] 24 |


Detailed Description

25 | 26 |

27 | 28 |

29 | Definition at line 165 of file pt-sem.h. 30 | 31 | 32 | 34 | 35 |

Data Fields

33 | unsigned int count
36 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  37 | 38 | doxygen 1.4.6
39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/html/a00007.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-addrlabels.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-addrlabels.h File Reference


Detailed Description

21 | Implementation of local continuations based on the "Labels as values" feature of gcc. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 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.

25 | For more information, see the GCC documentation: http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 26 |

27 | Definition in file lc-addrlabels.h. 28 |

29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 36 | 37 | 39 | 40 | 42 | 43 | 45 | 46 | 48 | 49 | 51 | 52 | 53 | 55 | 56 |

Defines

35 | #define LC_INIT(s)   s = NULL
38 | #define LC_RESUME(s)
41 | #define LC_CONCAT2(s1, s2)   s1##s2
44 | #define LC_CONCAT(s1, s2)   LC_CONCAT2(s1, s2)
47 | #define LC_SET(s)
50 | #define LC_END(s)

Typedefs

54 | typedef void * lc_t
57 |


Generated on Sat Jun 3 13:53:28 2006 for The Protothreads Library 1.3 by  58 | 59 | doxygen 1.4.6
60 | 61 | 62 | -------------------------------------------------------------------------------- /doc/html/a00008.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-switch.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-switch.h File Reference


Detailed Description

21 | Implementation of local continuations based on switch() statment. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 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.

25 | This implementation borrows heavily from Simon Tatham's coroutines implementation in C: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html 26 |

27 | Definition in file lc-switch.h. 28 |

29 | 30 |

31 | This graph shows which files directly or indirectly include this file:

32 | 33 | 34 | 35 | 36 | 37 | 38 |

39 | Go to the source code of this file. 40 | 41 | 42 | 44 | 45 | 47 | 48 | 50 | 51 | 53 | 54 | 55 | 57 | 58 | 59 |

Defines

43 | #define LC_INIT(s)   s = 0;
46 | #define LC_RESUME(s)   switch(s) { case 0:
49 | #define LC_SET(s)   s = __LINE__; case __LINE__:
52 | #define LC_END(s)   }

Typedefs

56 | typedef unsigned short lc_t
 The local continuation type.
60 |


Generated on Sat Jun 3 13:53:29 2006 for The Protothreads Library 1.3 by  61 | 62 | doxygen 1.4.6
63 | 64 | 65 | -------------------------------------------------------------------------------- /doc/html/a00009.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-addrlabels.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-addrlabels.h File Reference


Detailed Description

21 | Implementation of local continuations based on the "Labels as values" feature of gcc. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 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.

25 | For more information, see the GCC documentation: http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 26 |

27 | Definition in file lc-addrlabels.h. 28 |

29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 36 | 37 | 39 | 40 | 42 | 43 | 45 | 46 | 48 | 49 | 51 | 52 | 53 | 55 | 56 |

Defines

35 | #define LC_INIT(s)   s = NULL
38 | #define LC_RESUME(s)
41 | #define LC_CONCAT2(s1, s2)   s1##s2
44 | #define LC_CONCAT(s1, s2)   LC_CONCAT2(s1, s2)
47 | #define LC_SET(s)
50 | #define LC_END(s)

Typedefs

54 | typedef void * lc_t
57 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  58 | 59 | doxygen 1.4.6
60 | 61 | 62 | -------------------------------------------------------------------------------- /doc/html/a00010.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-switch.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-switch.h File Reference


Detailed Description

21 | Implementation of local continuations based on switch() statment. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 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.

25 | This implementation borrows heavily from Simon Tatham's coroutines implementation in C: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html 26 |

27 | Definition in file lc-switch.h. 28 |

29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 36 | 37 | 39 | 40 | 42 | 43 | 45 | 46 | 47 | 49 | 50 | 51 |

Defines

35 | #define LC_INIT(s)   s = 0;
38 | #define LC_RESUME(s)   switch(s) { case 0:
41 | #define LC_SET(s)   s = __LINE__; case __LINE__:
44 | #define LC_END(s)   }

Typedefs

48 | typedef unsigned short lc_t
 The local continuation type.
52 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  53 | 54 | doxygen 1.4.6
55 | 56 | 57 | -------------------------------------------------------------------------------- /doc/html/a00010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00010.png -------------------------------------------------------------------------------- /doc/html/a00011.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc.h File Reference


Detailed Description

21 | Local continuations. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 25 |

26 | Definition in file lc.h. 27 |

28 | #include "lc-switch.h"
29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |

Defines

#define LC_INIT(lc)
 Initialize a local continuation.
#define LC_SET(lc)
 Set a local continuation.
#define LC_RESUME(lc)
 Resume a local continuation.
#define LC_END(lc)
 Mark the end of local continuation usage.
47 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  48 | 49 | doxygen 1.4.6
50 | 51 | 52 | -------------------------------------------------------------------------------- /doc/html/a00012.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt-sem.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

pt-sem.h File Reference


Detailed Description

21 | Couting semaphores implemented on protothreads. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 25 |

26 | Definition in file pt-sem.h. 27 |

28 | #include "pt.h"
29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |

Data Structures

struct  pt_sem

Defines

#define PT_SEM_INIT(s, c)
 Initialize a semaphore.
#define PT_SEM_WAIT(pt, s)
 Wait for a semaphore.
#define PT_SEM_SIGNAL(pt, s)
 Signal a semaphore.
47 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  48 | 49 | doxygen 1.4.6
50 | 51 | 52 | -------------------------------------------------------------------------------- /doc/html/a00012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00012.png -------------------------------------------------------------------------------- /doc/html/a00013.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: pt.h File Reference 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

pt.h File Reference


Detailed Description

21 | Protothreads implementation. 22 |

23 |

Author:
Adam Dunkels <adam@sics.se>
24 | 25 |

26 | Definition in file pt.h. 27 |

28 | #include "lc.h"
29 | 30 |

31 | Go to the source code of this file. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 85 | 86 | 88 | 89 | 91 | 92 | 94 | 95 |

Data Structures

struct  pt

Initialization

#define PT_INIT(pt)
 Initialize a protothread.

Declaration and definition

#define PT_THREAD(name_args)
 Declaration of a protothread function.
#define PT_BEGIN(pt)
 Declare the start of a protothread inside the C function implementing the protothread.
#define PT_END(pt)
 Declare the end of a protothread.

Blocked wait

#define PT_WAIT_UNTIL(pt, condition)
 Block and wait until condition is true.
#define PT_WAIT_WHILE(pt, cond)
 Block and wait while condition is true.

Hierarchical protothreads

#define PT_WAIT_THREAD(pt, thread)
 Block and wait until a child protothread completes.
#define PT_SPAWN(pt, child, thread)
 Spawn a child protothread and wait until it exits.

Exiting and restarting

#define PT_RESTART(pt)
 Restart the protothread.
#define PT_EXIT(pt)
 Exit the protothread.

Calling a protothread

#define PT_SCHEDULE(f)
 Schedule a protothread.

Yielding from a protothread

#define PT_YIELD(pt)
 Yield from the current protothread.
#define PT_YIELD_UNTIL(pt, cond)
 Yield from the protothread until a condition occurs.

Defines

84 | #define PT_WAITING   0
87 | #define PT_EXITED   1
90 | #define PT_ENDED   2
93 | #define PT_YIELDED   3
96 |


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  97 | 98 | doxygen 1.4.6
99 | 100 | 101 | -------------------------------------------------------------------------------- /doc/html/a00013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00013.png -------------------------------------------------------------------------------- /doc/html/a00014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00014.png -------------------------------------------------------------------------------- /doc/html/a00015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00015.png -------------------------------------------------------------------------------- /doc/html/a00016.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00006.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00016.md5: -------------------------------------------------------------------------------- 1 | 3ed5f91a56231a0c80acf182e0076916 -------------------------------------------------------------------------------- /doc/html/a00016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00016.png -------------------------------------------------------------------------------- /doc/html/a00018.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-addrlabels.h Source File 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-addrlabels.h

Go to the documentation of this file.
00001 /*
 21 | 00002  * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
 22 | 00003  * All rights reserved.
 23 | 00004  *
 24 | 00005  * Redistribution and use in source and binary forms, with or without
 25 | 00006  * modification, are permitted provided that the following conditions
 26 | 00007  * are met:
 27 | 00008  * 1. Redistributions of source code must retain the above copyright
 28 | 00009  *    notice, this list of conditions and the following disclaimer.
 29 | 00010  * 2. Redistributions in binary form must reproduce the above copyright
 30 | 00011  *    notice, this list of conditions and the following disclaimer in the
 31 | 00012  *    documentation and/or other materials provided with the distribution.
 32 | 00013  * 3. Neither the name of the Institute nor the names of its contributors
 33 | 00014  *    may be used to endorse or promote products derived from this software
 34 | 00015  *    without specific prior written permission.
 35 | 00016  *
 36 | 00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 37 | 00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 38 | 00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 39 | 00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 40 | 00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 41 | 00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 42 | 00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 43 | 00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 44 | 00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 45 | 00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46 | 00027  * SUCH DAMAGE.
 47 | 00028  *
 48 | 00029  * This file is part of the Contiki operating system.
 49 | 00030  *
 50 | 00031  * Author: Adam Dunkels <adam@sics.se>
 51 | 00032  *
 52 | 00033  * $Id: lc-addrlabels.h,v 1.4 2006/06/03 11:29:43 adam Exp $
 53 | 00034  */
 54 | 00035 
 55 | 00036 /**
 56 | 00037  * \addtogroup lc
 57 | 00038  * @{
 58 | 00039  */
 59 | 00040 
 60 | 00041 /**
 61 | 00042  * \file
 62 | 00043  * Implementation of local continuations based on the "Labels as
 63 | 00044  * values" feature of gcc
 64 | 00045  * \author
 65 | 00046  * Adam Dunkels <adam@sics.se>
 66 | 00047  *
 67 | 00048  * This implementation of local continuations is based on a special
 68 | 00049  * feature of the GCC C compiler called "labels as values". This
 69 | 00050  * feature allows assigning pointers with the address of the code
 70 | 00051  * corresponding to a particular C label.
 71 | 00052  *
 72 | 00053  * For more information, see the GCC documentation:
 73 | 00054  * http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
 74 | 00055  *
 75 | 00056  */
 76 | 00057 
 77 | 00058 #ifndef __LC_ADDRLABELS_H__
 78 | 00059 #define __LC_ADDRLABELS_H__
 79 | 00060 
 80 | 00061 /** \hideinitializer */
 81 | 00062 typedef void * lc_t;
 82 | 00063 
 83 | 00064 #define LC_INIT(s) s = NULL
 84 | 00065 
 85 | 00066 #define LC_RESUME(s)                            \
 86 | 00067   do {                                          \
 87 | 00068     if(s != NULL) {                             \
 88 | 00069       goto *s;                                  \
 89 | 00070     }                                           \
 90 | 00071   } while(0)
 91 | 00072 
 92 | 00073 #define LC_CONCAT2(s1, s2) s1##s2
 93 | 00074 #define LC_CONCAT(s1, s2) LC_CONCAT2(s1, s2)
 94 | 00075 
 95 | 00076 #define LC_SET(s)                               \
 96 | 00077   do {                                          \
 97 | 00078     LC_CONCAT(LC_LABEL, __LINE__):              \
 98 | 00079     (s) = &&LC_CONCAT(LC_LABEL, __LINE__);      \
 99 | 00080   } while(0)
100 | 00081 
101 | 00082 #define LC_END(s)
102 | 00083 
103 | 00084 #endif /* __LC_ADDRLABELS_H__ */
104 | 00085 /** @} */
105 | 

Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  106 | 107 | doxygen 1.4.6
108 | 109 | 110 | -------------------------------------------------------------------------------- /doc/html/a00018.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00007.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00018.md5: -------------------------------------------------------------------------------- 1 | f20380e1b42baf605f9185fee153d636 -------------------------------------------------------------------------------- /doc/html/a00018.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00018.png -------------------------------------------------------------------------------- /doc/html/a00019.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc-switch.h Source File 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc-switch.h

Go to the documentation of this file.
00001 /*
 21 | 00002  * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
 22 | 00003  * All rights reserved.
 23 | 00004  *
 24 | 00005  * Redistribution and use in source and binary forms, with or without
 25 | 00006  * modification, are permitted provided that the following conditions
 26 | 00007  * are met:
 27 | 00008  * 1. Redistributions of source code must retain the above copyright
 28 | 00009  *    notice, this list of conditions and the following disclaimer.
 29 | 00010  * 2. Redistributions in binary form must reproduce the above copyright
 30 | 00011  *    notice, this list of conditions and the following disclaimer in the
 31 | 00012  *    documentation and/or other materials provided with the distribution.
 32 | 00013  * 3. Neither the name of the Institute nor the names of its contributors
 33 | 00014  *    may be used to endorse or promote products derived from this software
 34 | 00015  *    without specific prior written permission.
 35 | 00016  *
 36 | 00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 37 | 00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 38 | 00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 39 | 00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 40 | 00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 41 | 00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 42 | 00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 43 | 00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 44 | 00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 45 | 00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46 | 00027  * SUCH DAMAGE.
 47 | 00028  *
 48 | 00029  * This file is part of the Contiki operating system.
 49 | 00030  *
 50 | 00031  * Author: Adam Dunkels <adam@sics.se>
 51 | 00032  *
 52 | 00033  * $Id: lc-switch.h,v 1.4 2006/06/03 11:29:43 adam Exp $
 53 | 00034  */
 54 | 00035 
 55 | 00036 /**
 56 | 00037  * \addtogroup lc
 57 | 00038  * @{
 58 | 00039  */
 59 | 00040 
 60 | 00041 /**
 61 | 00042  * \file
 62 | 00043  * Implementation of local continuations based on switch() statment
 63 | 00044  * \author Adam Dunkels <adam@sics.se>
 64 | 00045  *
 65 | 00046  * This implementation of local continuations uses the C switch()
 66 | 00047  * statement to resume execution of a function somewhere inside the
 67 | 00048  * function's body. The implementation is based on the fact that
 68 | 00049  * switch() statements are able to jump directly into the bodies of
 69 | 00050  * control structures such as if() or while() statmenets.
 70 | 00051  *
 71 | 00052  * This implementation borrows heavily from Simon Tatham's coroutines
 72 | 00053  * implementation in C:
 73 | 00054  * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
 74 | 00055  */
 75 | 00056 
 76 | 00057 #ifndef __LC_SWITCH_H__
 77 | 00058 #define __LC_SWITCH_H__
 78 | 00059 
 79 | 00060 /* WARNING! lc implementation using switch() does not work if an
 80 | 00061    LC_SET() is done within another switch() statement! */
 81 | 00062 
 82 | 00063 /** \hideinitializer */
 83 | 00064 typedef unsigned short lc_t;
 84 | 00065 
 85 | 00066 #define LC_INIT(s) s = 0;
 86 | 00067 
 87 | 00068 #define LC_RESUME(s) switch(s) { case 0:
 88 | 00069 
 89 | 00070 #define LC_SET(s) s = __LINE__; case __LINE__:
 90 | 00071 
 91 | 00072 #define LC_END(s) }
 92 | 00073 
 93 | 00074 #endif /* __LC_SWITCH_H__ */
 94 | 00075 
 95 | 00076 /** @} */
 96 | 

Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  97 | 98 | doxygen 1.4.6
99 | 100 | 101 | -------------------------------------------------------------------------------- /doc/html/a00020.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: lc.h Source File 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

lc.h

Go to the documentation of this file.
00001 /*
 21 | 00002  * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
 22 | 00003  * All rights reserved. 
 23 | 00004  *
 24 | 00005  * Redistribution and use in source and binary forms, with or without 
 25 | 00006  * modification, are permitted provided that the following conditions 
 26 | 00007  * are met: 
 27 | 00008  * 1. Redistributions of source code must retain the above copyright 
 28 | 00009  *    notice, this list of conditions and the following disclaimer. 
 29 | 00010  * 2. Redistributions in binary form must reproduce the above copyright 
 30 | 00011  *    notice, this list of conditions and the following disclaimer in the 
 31 | 00012  *    documentation and/or other materials provided with the distribution. 
 32 | 00013  * 3. Neither the name of the Institute nor the names of its contributors 
 33 | 00014  *    may be used to endorse or promote products derived from this software 
 34 | 00015  *    without specific prior written permission. 
 35 | 00016  *
 36 | 00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
 37 | 00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 38 | 00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 39 | 00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
 40 | 00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 41 | 00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 42 | 00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 43 | 00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 44 | 00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 45 | 00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 46 | 00027  * SUCH DAMAGE. 
 47 | 00028  *
 48 | 00029  * This file is part of the protothreads library.
 49 | 00030  * 
 50 | 00031  * Author: Adam Dunkels <adam@sics.se>
 51 | 00032  *
 52 | 00033  * $Id: lc.h,v 1.2 2005/02/24 10:36:59 adam Exp $
 53 | 00034  */
 54 | 00035 
 55 | 00036 /**
 56 | 00037  * \addtogroup pt
 57 | 00038  * @{
 58 | 00039  */
 59 | 00040 
 60 | 00041 /**
 61 | 00042  * \defgroup lc Local continuations
 62 | 00043  * @{
 63 | 00044  *
 64 | 00045  * Local continuations form the basis for implementing protothreads. A
 65 | 00046  * local continuation can be <i>set</i> in a specific function to
 66 | 00047  * capture the state of the function. After a local continuation has
 67 | 00048  * been set can be <i>resumed</i> in order to restore the state of the
 68 | 00049  * function at the point where the local continuation was set.
 69 | 00050  *
 70 | 00051  *
 71 | 00052  */
 72 | 00053 
 73 | 00054 /**
 74 | 00055  * \file lc.h
 75 | 00056  * Local continuations
 76 | 00057  * \author
 77 | 00058  * Adam Dunkels <adam@sics.se>
 78 | 00059  *
 79 | 00060  */
 80 | 00061 
 81 | 00062 #ifdef DOXYGEN
 82 | 00063 /**
 83 | 00064  * Initialize a local continuation.
 84 | 00065  *
 85 | 00066  * This operation initializes the local continuation, thereby
 86 | 00067  * unsetting any previously set continuation state.
 87 | 00068  *
 88 | 00069  * \hideinitializer
 89 | 00070  */
 90 | 00071 #define LC_INIT(lc)
 91 | 00072 
 92 | 00073 /**
 93 | 00074  * Set a local continuation.
 94 | 00075  *
 95 | 00076  * The set operation saves the state of the function at the point
 96 | 00077  * where the operation is executed. As far as the set operation is
 97 | 00078  * concerned, the state of the function does <b>not</b> include the
 98 | 00079  * call-stack or local (automatic) variables, but only the program
 99 | 00080  * counter and such CPU registers that needs to be saved.
100 | 00081  *
101 | 00082  * \hideinitializer
102 | 00083  */
103 | 00084 #define LC_SET(lc)
104 | 00085 
105 | 00086 /**
106 | 00087  * Resume a local continuation.
107 | 00088  *
108 | 00089  * The resume operation resumes a previously set local continuation, thus
109 | 00090  * restoring the state in which the function was when the local
110 | 00091  * continuation was set. If the local continuation has not been
111 | 00092  * previously set, the resume operation does nothing.
112 | 00093  *
113 | 00094  * \hideinitializer
114 | 00095  */
115 | 00096 #define LC_RESUME(lc)
116 | 00097 
117 | 00098 /**
118 | 00099  * Mark the end of local continuation usage.
119 | 00100  *
120 | 00101  * The end operation signifies that local continuations should not be
121 | 00102  * used any more in the function. This operation is not needed for
122 | 00103  * most implementations of local continuation, but is required by a
123 | 00104  * few implementations.
124 | 00105  *
125 | 00106  * \hideinitializer 
126 | 00107  */
127 | 00108 #define LC_END(lc)
128 | 00109 
129 | 00110 /**
130 | 00111  * \var typedef lc_t;
131 | 00112  *
132 | 00113  * The local continuation type.
133 | 00114  *
134 | 00115  * \hideinitializer
135 | 00116  */
136 | 00117 #endif /* DOXYGEN */
137 | 00118 
138 | 00119 #ifndef __LC_H__
139 | 00120 #define __LC_H__
140 | 00121 
141 | 00122 
142 | 00123 #ifdef LC_INCLUDE
143 | 00124 #include LC_INCLUDE
144 | 00125 #else
145 | 00126 #include "lc-switch.h"
146 | 00127 #endif /* LC_INCLUDE */
147 | 00128 
148 | 00129 #endif /* __LC_H__ */
149 | 00130 
150 | 00131 /** @} */
151 | 00132 /** @} */
152 | 

Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  153 | 154 | doxygen 1.4.6
155 | 156 | 157 | -------------------------------------------------------------------------------- /doc/html/a00020.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00008.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00020.md5: -------------------------------------------------------------------------------- 1 | bd4cd2ba01855dff6417848f3f6c7aec -------------------------------------------------------------------------------- /doc/html/a00020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00020.png -------------------------------------------------------------------------------- /doc/html/a00022.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00008.html 22,167 60,193 3 | rect $a00010.html 22,92 60,119 4 | rect $a00009.html 12,17 70,44 5 | -------------------------------------------------------------------------------- /doc/html/a00022.md5: -------------------------------------------------------------------------------- 1 | e7f5720780518387d34a467b607d9b90 -------------------------------------------------------------------------------- /doc/html/a00022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00022.png -------------------------------------------------------------------------------- /doc/html/a00023.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00009.html 140,7 183,33 3 | rect $a00011.html 232,7 275,33 4 | rect $a00010.html 324,7 399,33 5 | -------------------------------------------------------------------------------- /doc/html/a00023.md5: -------------------------------------------------------------------------------- 1 | 5ab9824cd3b0987bf31e680366320e9d -------------------------------------------------------------------------------- /doc/html/a00023.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00023.png -------------------------------------------------------------------------------- /doc/html/a00024.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00009.html 22,167 60,193 3 | rect $a00011.html 22,92 60,119 4 | rect $a00010.html 12,17 70,44 5 | -------------------------------------------------------------------------------- /doc/html/a00024.md5: -------------------------------------------------------------------------------- 1 | eb009dcaf1f86bba70bf0a2fee1b6718 -------------------------------------------------------------------------------- /doc/html/a00024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00024.png -------------------------------------------------------------------------------- /doc/html/a00025.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00011.html 99,7 141,33 3 | rect $a00010.html 191,7 265,33 4 | -------------------------------------------------------------------------------- /doc/html/a00025.md5: -------------------------------------------------------------------------------- 1 | 8c94d9ac7531cd68e60a4b13305f981b -------------------------------------------------------------------------------- /doc/html/a00025.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00025.png -------------------------------------------------------------------------------- /doc/html/a00026.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00010.html 100,7 175,33 3 | -------------------------------------------------------------------------------- /doc/html/a00026.md5: -------------------------------------------------------------------------------- 1 | 24396855ecb3edac469fb1d37f8fd048 -------------------------------------------------------------------------------- /doc/html/a00026.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00026.png -------------------------------------------------------------------------------- /doc/html/a00027.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00010.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00027.md5: -------------------------------------------------------------------------------- 1 | 5c32069d31d9ae5eca1bff9dd07aa925 -------------------------------------------------------------------------------- /doc/html/a00027.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00027.png -------------------------------------------------------------------------------- /doc/html/a00028.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00010.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00028.md5: -------------------------------------------------------------------------------- 1 | 5c32069d31d9ae5eca1bff9dd07aa925 -------------------------------------------------------------------------------- /doc/html/a00028.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00028.png -------------------------------------------------------------------------------- /doc/html/a00029.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00011.html 7,17 65,44 3 | -------------------------------------------------------------------------------- /doc/html/a00029.md5: -------------------------------------------------------------------------------- 1 | ad4ed891d9c8541c1dcc11643715809a -------------------------------------------------------------------------------- /doc/html/a00029.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00029.png -------------------------------------------------------------------------------- /doc/html/a00040.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00003.html 8,7 45,33 3 | -------------------------------------------------------------------------------- /doc/html/a00040.md5: -------------------------------------------------------------------------------- 1 | c2ac76415929576c0053d5224c8f9615 -------------------------------------------------------------------------------- /doc/html/a00040.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00040.png -------------------------------------------------------------------------------- /doc/html/a00042.map: -------------------------------------------------------------------------------- 1 | base referer 2 | rect $a00004.html 7,7 73,33 3 | -------------------------------------------------------------------------------- /doc/html/a00042.md5: -------------------------------------------------------------------------------- 1 | d8e28b3fd0a18c0729ecf601a5332d38 -------------------------------------------------------------------------------- /doc/html/a00042.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/a00042.png -------------------------------------------------------------------------------- /doc/html/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Structures 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

The Protothreads Library 1.3 Data Structures

Here are the data structures with brief descriptions: 22 | 23 | 24 |
pt
pt_sem
25 |
Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  26 | 27 | doxygen 1.4.6
28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/html/doxygen.css: -------------------------------------------------------------------------------- 1 | BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV { 2 | font-family: Geneva, Arial, Helvetica, sans-serif; 3 | } 4 | BODY,TD { 5 | font-size: 90%; 6 | } 7 | H1 { 8 | text-align: center; 9 | font-size: 160%; 10 | } 11 | H2 { 12 | font-size: 120%; 13 | } 14 | H3 { 15 | font-size: 100%; 16 | } 17 | CAPTION { font-weight: bold } 18 | DIV.qindex { 19 | width: 100%; 20 | background-color: #e8eef2; 21 | border: 1px solid #84b0c7; 22 | text-align: center; 23 | margin: 2px; 24 | padding: 2px; 25 | line-height: 140%; 26 | } 27 | DIV.nav { 28 | width: 100%; 29 | background-color: #e8eef2; 30 | border: 1px solid #84b0c7; 31 | text-align: center; 32 | margin: 2px; 33 | padding: 2px; 34 | line-height: 140%; 35 | } 36 | DIV.navtab { 37 | background-color: #e8eef2; 38 | border: 1px solid #84b0c7; 39 | text-align: center; 40 | margin: 2px; 41 | margin-right: 15px; 42 | padding: 2px; 43 | } 44 | TD.navtab { 45 | font-size: 70%; 46 | } 47 | A.qindex { 48 | text-decoration: none; 49 | font-weight: bold; 50 | color: #1A419D; 51 | } 52 | A.qindex:visited { 53 | text-decoration: none; 54 | font-weight: bold; 55 | color: #1A419D 56 | } 57 | A.qindex:hover { 58 | text-decoration: none; 59 | background-color: #ddddff; 60 | } 61 | A.qindexHL { 62 | text-decoration: none; 63 | font-weight: bold; 64 | background-color: #6666cc; 65 | color: #ffffff; 66 | border: 1px double #9295C2; 67 | } 68 | A.qindexHL:hover { 69 | text-decoration: none; 70 | background-color: #6666cc; 71 | color: #ffffff; 72 | } 73 | A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff } 74 | A.el { text-decoration: none; font-weight: bold } 75 | A.elRef { font-weight: bold } 76 | A.code:link { text-decoration: none; font-weight: normal; color: #0000FF} 77 | A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF} 78 | A.codeRef:link { font-weight: normal; color: #0000FF} 79 | A.codeRef:visited { font-weight: normal; color: #0000FF} 80 | A:hover { text-decoration: none; background-color: #f2f2ff } 81 | DL.el { margin-left: -1cm } 82 | .fragment { 83 | font-family: Fixed, monospace; 84 | font-size: 95%; 85 | } 86 | PRE.fragment { 87 | border: 1px solid #CCCCCC; 88 | background-color: #f5f5f5; 89 | margin-top: 4px; 90 | margin-bottom: 4px; 91 | margin-left: 2px; 92 | margin-right: 8px; 93 | padding-left: 6px; 94 | padding-right: 6px; 95 | padding-top: 4px; 96 | padding-bottom: 4px; 97 | } 98 | DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px } 99 | TD.md { background-color: #F4F4FB; font-weight: bold; } 100 | TD.mdPrefix { 101 | background-color: #F4F4FB; 102 | color: #606060; 103 | font-size: 80%; 104 | } 105 | TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; } 106 | TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; } 107 | DIV.groupHeader { 108 | margin-left: 16px; 109 | margin-top: 12px; 110 | margin-bottom: 6px; 111 | font-weight: bold; 112 | } 113 | DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% } 114 | BODY { 115 | background: white; 116 | color: black; 117 | margin-right: 20px; 118 | margin-left: 20px; 119 | } 120 | TD.indexkey { 121 | background-color: #e8eef2; 122 | font-weight: bold; 123 | padding-right : 10px; 124 | padding-top : 2px; 125 | padding-left : 10px; 126 | padding-bottom : 2px; 127 | margin-left : 0px; 128 | margin-right : 0px; 129 | margin-top : 2px; 130 | margin-bottom : 2px; 131 | border: 1px solid #CCCCCC; 132 | } 133 | TD.indexvalue { 134 | background-color: #e8eef2; 135 | font-style: italic; 136 | padding-right : 10px; 137 | padding-top : 2px; 138 | padding-left : 10px; 139 | padding-bottom : 2px; 140 | margin-left : 0px; 141 | margin-right : 0px; 142 | margin-top : 2px; 143 | margin-bottom : 2px; 144 | border: 1px solid #CCCCCC; 145 | } 146 | TR.memlist { 147 | background-color: #f0f0f0; 148 | } 149 | P.formulaDsp { text-align: center; } 150 | IMG.formulaDsp { } 151 | IMG.formulaInl { vertical-align: middle; } 152 | SPAN.keyword { color: #008000 } 153 | SPAN.keywordtype { color: #604020 } 154 | SPAN.keywordflow { color: #e08000 } 155 | SPAN.comment { color: #800000 } 156 | SPAN.preprocessor { color: #806020 } 157 | SPAN.stringliteral { color: #002080 } 158 | SPAN.charliteral { color: #008080 } 159 | .mdTable { 160 | border: 1px solid #868686; 161 | background-color: #F4F4FB; 162 | } 163 | .mdRow { 164 | padding: 8px 10px; 165 | } 166 | .mdescLeft { 167 | padding: 0px 8px 4px 8px; 168 | font-size: 80%; 169 | font-style: italic; 170 | background-color: #FAFAFA; 171 | border-top: 1px none #E0E0E0; 172 | border-right: 1px none #E0E0E0; 173 | border-bottom: 1px none #E0E0E0; 174 | border-left: 1px none #E0E0E0; 175 | margin: 0px; 176 | } 177 | .mdescRight { 178 | padding: 0px 8px 4px 8px; 179 | font-size: 80%; 180 | font-style: italic; 181 | background-color: #FAFAFA; 182 | border-top: 1px none #E0E0E0; 183 | border-right: 1px none #E0E0E0; 184 | border-bottom: 1px none #E0E0E0; 185 | border-left: 1px none #E0E0E0; 186 | margin: 0px; 187 | } 188 | .memItemLeft { 189 | padding: 1px 0px 0px 8px; 190 | margin: 4px; 191 | border-top-width: 1px; 192 | border-right-width: 1px; 193 | border-bottom-width: 1px; 194 | border-left-width: 1px; 195 | border-top-color: #E0E0E0; 196 | border-right-color: #E0E0E0; 197 | border-bottom-color: #E0E0E0; 198 | border-left-color: #E0E0E0; 199 | border-top-style: solid; 200 | border-right-style: none; 201 | border-bottom-style: none; 202 | border-left-style: none; 203 | background-color: #FAFAFA; 204 | font-size: 80%; 205 | } 206 | .memItemRight { 207 | padding: 1px 8px 0px 8px; 208 | margin: 4px; 209 | border-top-width: 1px; 210 | border-right-width: 1px; 211 | border-bottom-width: 1px; 212 | border-left-width: 1px; 213 | border-top-color: #E0E0E0; 214 | border-right-color: #E0E0E0; 215 | border-bottom-color: #E0E0E0; 216 | border-left-color: #E0E0E0; 217 | border-top-style: solid; 218 | border-right-style: none; 219 | border-bottom-style: none; 220 | border-left-style: none; 221 | background-color: #FAFAFA; 222 | font-size: 80%; 223 | } 224 | .memTemplItemLeft { 225 | padding: 1px 0px 0px 8px; 226 | margin: 4px; 227 | border-top-width: 1px; 228 | border-right-width: 1px; 229 | border-bottom-width: 1px; 230 | border-left-width: 1px; 231 | border-top-color: #E0E0E0; 232 | border-right-color: #E0E0E0; 233 | border-bottom-color: #E0E0E0; 234 | border-left-color: #E0E0E0; 235 | border-top-style: none; 236 | border-right-style: none; 237 | border-bottom-style: none; 238 | border-left-style: none; 239 | background-color: #FAFAFA; 240 | font-size: 80%; 241 | } 242 | .memTemplItemRight { 243 | padding: 1px 8px 0px 8px; 244 | margin: 4px; 245 | border-top-width: 1px; 246 | border-right-width: 1px; 247 | border-bottom-width: 1px; 248 | border-left-width: 1px; 249 | border-top-color: #E0E0E0; 250 | border-right-color: #E0E0E0; 251 | border-bottom-color: #E0E0E0; 252 | border-left-color: #E0E0E0; 253 | border-top-style: none; 254 | border-right-style: none; 255 | border-bottom-style: none; 256 | border-left-style: none; 257 | background-color: #FAFAFA; 258 | font-size: 80%; 259 | } 260 | .memTemplParams { 261 | padding: 1px 0px 0px 8px; 262 | margin: 4px; 263 | border-top-width: 1px; 264 | border-right-width: 1px; 265 | border-bottom-width: 1px; 266 | border-left-width: 1px; 267 | border-top-color: #E0E0E0; 268 | border-right-color: #E0E0E0; 269 | border-bottom-color: #E0E0E0; 270 | border-left-color: #E0E0E0; 271 | border-top-style: solid; 272 | border-right-style: none; 273 | border-bottom-style: none; 274 | border-left-style: none; 275 | color: #606060; 276 | background-color: #FAFAFA; 277 | font-size: 80%; 278 | } 279 | .search { color: #003399; 280 | font-weight: bold; 281 | } 282 | FORM.search { 283 | margin-bottom: 0px; 284 | margin-top: 0px; 285 | } 286 | INPUT.search { font-size: 75%; 287 | color: #000080; 288 | font-weight: normal; 289 | background-color: #e8eef2; 290 | } 291 | TD.tiny { font-size: 75%; 292 | } 293 | a { 294 | color: #1A41A8; 295 | } 296 | a:visited { 297 | color: #2A3798; 298 | } 299 | .dirtab { padding: 4px; 300 | border-collapse: collapse; 301 | border: 1px solid #84b0c7; 302 | } 303 | TH.dirtab { background: #e8eef2; 304 | font-weight: bold; 305 | } 306 | HR { height: 1px; 307 | border: none; 308 | border-top: 1px solid black; 309 | } 310 | 311 | -------------------------------------------------------------------------------- /doc/html/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/doxygen.png -------------------------------------------------------------------------------- /doc/html/examples.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.0: Example Index 4 | 5 | 6 | 7 | 8 |

The Protothreads Library 1.0 Examples

Here is a list of all examples: 11 |
Generated on Thu Mar 10 14:14:52 2005 for The Protothreads Library 1.0 by 12 | 13 | doxygen 14 | 1.3.6
15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/html/files.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: File Index 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |

The Protothreads Library 1.3 File List

Here is a list of all documented files with brief descriptions: 21 | 22 | 23 | 24 | 25 | 26 |
lc-addrlabels.h [code]Implementation of local continuations based on the "Labels as values" feature of gcc
lc-switch.h [code]Implementation of local continuations based on switch() statment
lc.h [code]Local continuations
pt-sem.h [code]Couting semaphores implemented on protothreads
pt.h [code]Protothreads implementation
27 |
Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  28 | 29 | doxygen 1.4.6
30 | 31 | 32 | -------------------------------------------------------------------------------- /doc/html/ftv2blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2blank.png -------------------------------------------------------------------------------- /doc/html/ftv2doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2doc.png -------------------------------------------------------------------------------- /doc/html/ftv2folderclosed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2folderclosed.png -------------------------------------------------------------------------------- /doc/html/ftv2folderopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2folderopen.png -------------------------------------------------------------------------------- /doc/html/ftv2lastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2lastnode.png -------------------------------------------------------------------------------- /doc/html/ftv2link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2link.png -------------------------------------------------------------------------------- /doc/html/ftv2mlastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2mlastnode.png -------------------------------------------------------------------------------- /doc/html/ftv2mnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2mnode.png -------------------------------------------------------------------------------- /doc/html/ftv2node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2node.png -------------------------------------------------------------------------------- /doc/html/ftv2plastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2plastnode.png -------------------------------------------------------------------------------- /doc/html/ftv2pnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2pnode.png -------------------------------------------------------------------------------- /doc/html/ftv2vertline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/ftv2vertline.png -------------------------------------------------------------------------------- /doc/html/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Fields 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |
22 | 26 |
27 | Here is a list of all documented struct and union fields with links to the struct/union documentation for each field: 28 |

29 |

33 |
Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  34 | 35 | doxygen 1.4.6
36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/html/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Fields - Variables 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |
22 | 26 |
27 |   28 |

29 |

33 |
Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  34 | 35 | doxygen 1.4.6
36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/html/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Fields 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |
21 | 26 |
27 | Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation: 28 |

29 |

58 |
Generated on Sat Jun 3 22:11:21 2006 for The Protothreads Library 1.3 by  59 | 60 | doxygen 1.4.6
61 | 62 | 63 | -------------------------------------------------------------------------------- /doc/html/globals_defs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Fields 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |
21 | 26 |
27 |   28 |

29 |

57 |
Generated on Sat Jun 3 22:11:21 2006 for The Protothreads Library 1.3 by  58 | 59 | doxygen 1.4.6
60 | 61 | 62 | -------------------------------------------------------------------------------- /doc/html/globals_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Data Fields 4 | 5 | 6 | 7 | 8 |
9 |
15 |
16 |
20 |
21 | 26 |
27 |   28 |

29 |

32 |
Generated on Sat Jun 3 22:11:21 2006 for The Protothreads Library 1.3 by  33 | 34 | doxygen 1.4.6
35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/graph_legend.dot: -------------------------------------------------------------------------------- 1 | digraph G 2 | { 3 | edge [fontname="Helvetica",fontsize=10,labelfontname="Helvetica",labelfontsize=10]; 4 | node [fontname="Helvetica",fontsize=10,shape=record]; 5 | Node9 [shape="box",label="Inherited",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",style="filled" fontcolor="white"]; 6 | Node10 -> Node9 [dir=back,color="midnightblue",fontsize=10,style="solid",fontname="Helvetica"]; 7 | Node10 [shape="box",label="PublicBase",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classPublicBase.html"]; 8 | Node11 -> Node10 [dir=back,color="midnightblue",fontsize=10,style="solid",fontname="Helvetica"]; 9 | Node11 [shape="box",label="Truncated",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="red",URL="$classTruncated.html"]; 10 | Node13 -> Node9 [dir=back,color="darkgreen",fontsize=10,style="solid",fontname="Helvetica"]; 11 | Node13 [shape="box",label="ProtectedBase",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classProtectedBase.html"]; 12 | Node14 -> Node9 [dir=back,color="firebrick4",fontsize=10,style="solid",fontname="Helvetica"]; 13 | Node14 [shape="box",label="PrivateBase",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classPrivateBase.html"]; 14 | Node15 -> Node9 [dir=back,color="midnightblue",fontsize=10,style="solid",fontname="Helvetica"]; 15 | Node15 [shape="box",label="Undocumented",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="grey75"]; 16 | Node16 -> Node9 [dir=back,color="midnightblue",fontsize=10,style="solid",fontname="Helvetica"]; 17 | Node16 [shape="box",label="Templ< int >",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classTempl.html"]; 18 | Node17 -> Node16 [dir=back,color="orange",fontsize=10,style="dashed",label="< int >",fontname="Helvetica"]; 19 | Node17 [shape="box",label="Templ< T >",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classTempl.html"]; 20 | Node18 -> Node9 [dir=back,color="darkorchid3",fontsize=10,style="dashed",label="m_usedClass",fontname="Helvetica"]; 21 | Node18 [shape="box",label="Used",fontsize=10,height=0.2,width=0.4,fontname="Helvetica",color="black",URL="$classUsed.html"]; 22 | } 23 | -------------------------------------------------------------------------------- /doc/html/graph_legend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Graph Legend 4 | 5 | 6 | 7 | 8 |
9 |
15 |

Graph Legend

This page explains how to interpret the graphs that are generated by doxygen.

16 | Consider the following example:

/*! Invisible class because of truncation */
17 | class Invisible { };
18 | 
19 | /*! Truncated class, inheritance relation is hidden */
20 | class Truncated : public Invisible { };
21 | 
22 | /* Class not documented with doxygen comments */
23 | class Undocumented { };
24 | 
25 | /*! Class that is inherited using public inheritance */
26 | class PublicBase : public Truncated { };
27 | 
28 | /*! A template class */
29 | template<class T> class Templ { };
30 | 
31 | /*! Class that is inherited using protected inheritance */
32 | class ProtectedBase { };
33 | 
34 | /*! Class that is inherited using private inheritance */
35 | class PrivateBase { };
36 | 
37 | /*! Class that is used by the Inherited class */
38 | class Used { };
39 | 
40 | /*! Super class that inherits a number of other classes */
41 | class Inherited : public PublicBase,
42 |                   protected ProtectedBase,
43 |                   private PrivateBase,
44 |                   public Undocumented
45 |                   public Templ<int>
46 | {
47 |   private:
48 |     Used *m_usedClass;
49 | };
50 | 
If the MAX_DOT_GRAPH_HEIGHT tag in the configuration file is set to 240 this will result in the following graph:

51 |

52 | graph_legend.png 53 |
54 |

55 | The boxes in the above graph have the following meaning:

65 | The arrows have the following meaning: 77 |
Generated on Sat Jun 3 13:53:34 2006 for The Protothreads Library 1.3 by  78 | 79 | doxygen 1.4.6
80 | 81 | 82 | -------------------------------------------------------------------------------- /doc/html/graph_legend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/graph_legend.png -------------------------------------------------------------------------------- /doc/html/hierarchy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Hierarchical Index 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

The Protothreads Library 1.3 Class Hierarchy

This inheritance list is sorted roughly, but not completely, alphabetically: 25 |
Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  26 | 27 | doxygen 1.4.6
28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/html/index.hhc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 44 | -------------------------------------------------------------------------------- /doc/html/index.hhk: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 57 | -------------------------------------------------------------------------------- /doc/html/index.hhp: -------------------------------------------------------------------------------- 1 | [OPTIONS] 2 | Compatibility=1.1 3 | Full-text search=Yes 4 | Contents file=index.hhc 5 | Default Window=main 6 | Default topic=main.html 7 | Index file=index.hhk 8 | Language=0x409 English (United States) 9 | Title=The Protothreads Library 1.3 10 | 11 | [WINDOWS] 12 | main="The Protothreads Library 1.3","index.hhc","index.hhk","main.html","main.html",,,,,0x23520,,0x387e,,,,,,,,0 13 | 14 | [FILES] 15 | main.html 16 | files.html 17 | a00018.html 18 | a00019.html 19 | a00020.html 20 | a00021.html 21 | a00022.html 22 | a00009.html 23 | a00010.html 24 | a00011.html 25 | a00012.html 26 | a00013.html 27 | annotated.html 28 | hierarchy.html 29 | functions.html 30 | functions_vars.html 31 | a00005.html 32 | a00006.html 33 | a00014.html 34 | a00015.html 35 | a00016.html 36 | a00017.html 37 | modules.html 38 | globals.html 39 | globals_type.html 40 | globals_defs.html 41 | tabs.css 42 | tab_b.gif 43 | tab_l.gif 44 | tab_r.gif 45 | -------------------------------------------------------------------------------- /doc/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/html/inherits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Graphical Class Hierarchy 4 | 5 | 6 | 7 | 8 |
9 |
15 | 21 |

The Protothreads Library 1.3 Graphical Class Hierarchy

Go to the textual class hierarchy 22 |

23 | 24 | 28 | 32 |
25 | 26 | 27 |
29 | 30 | 31 |
33 |


Generated on Sat Jun 3 13:53:34 2006 for The Protothreads Library 1.3 by  34 | 35 | doxygen 1.4.6
36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/html/main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: The Protothreads Library 4 | 5 | 6 | 7 | 8 |
9 |
15 |

The Protothreads Library

16 |

17 |

Author:
Adam Dunkels <adam@sics.se>
18 | 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.

19 | 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.

20 | Main features:

21 |

23 |

24 |

26 |

27 |

29 |

30 |

32 |

33 |

35 |

36 | Examples applications:

37 |

39 |

40 |

42 |

43 |

45 |

46 |

48 |

49 |

See also:
Example programs

50 | Protothreads API documentation

51 | 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.

52 | More information and new version of the code can be found at the Protothreads homepage:

53 | http://www.sics.se/~adam/pt/

54 | Authors

55 | The protothreads library was written by Adam Dunkels <adam@sics.se> with support from Oliver Schmidt <ol.sc@web.de>.

56 | Using protothreads

57 | 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.

58 | Protothreads

59 | 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.

60 | 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.

61 | 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.

62 | 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.

63 | 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.

64 | Local variables

65 |
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!
66 |

67 | Scheduling

68 | 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.

69 | Implementation

70 | 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.

71 | Local continuations can be implemented in a variety of ways:

72 |

    73 |
  1. by using machine specific assembler code,
  2. by using standard C constructs, or
  3. by using compiler extensions.
74 |

75 | 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.

76 | 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.

77 | 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.


Generated on Sat Jun 3 22:11:20 2006 for The Protothreads Library 1.3 by  78 | 79 | doxygen 1.4.6
80 | 81 | 82 | -------------------------------------------------------------------------------- /doc/html/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.3: Module Index 4 | 5 | 6 | 7 | 8 |
9 |
15 |

The Protothreads Library 1.3 Modules

Here is a list of all modules: 23 |
Generated on Sat Jun 3 22:11:21 2006 for The Protothreads Library 1.3 by  24 | 25 | doxygen 1.4.6
26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/html/pages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.0: Page Index 4 | 5 | 6 | 7 | 8 |

The Protothreads Library 1.0 Related Pages

Here is a list of all related documentation pages: 12 |
Generated on Thu Feb 24 01:34:15 2005 for The Protothreads Library 1.0 by 13 | 14 | doxygen 15 | 1.3.6
16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/html/tab_b.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/tab_b.gif -------------------------------------------------------------------------------- /doc/html/tab_l.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/tab_l.gif -------------------------------------------------------------------------------- /doc/html/tab_r.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/html/tab_r.gif -------------------------------------------------------------------------------- /doc/html/tabs.css: -------------------------------------------------------------------------------- 1 | /* tabs styles, based on http://www.alistapart.com/articles/slidingdoors */ 2 | 3 | DIV.tabs 4 | { 5 | float : left; 6 | width : 100%; 7 | background : url("tab_b.gif") repeat-x bottom; 8 | margin-bottom : 4px; 9 | } 10 | 11 | DIV.tabs UL 12 | { 13 | margin : 0px; 14 | padding-left : 10px; 15 | list-style : none; 16 | } 17 | 18 | DIV.tabs LI, DIV.tabs FORM 19 | { 20 | display : inline; 21 | margin : 0px; 22 | padding : 0px; 23 | } 24 | 25 | DIV.tabs FORM 26 | { 27 | float : right; 28 | } 29 | 30 | DIV.tabs A 31 | { 32 | float : left; 33 | background : url("tab_r.gif") no-repeat right top; 34 | border-bottom : 1px solid #84B0C7; 35 | font-size : x-small; 36 | font-weight : bold; 37 | text-decoration : none; 38 | } 39 | 40 | DIV.tabs A:hover 41 | { 42 | background-position: 100% -150px; 43 | } 44 | 45 | DIV.tabs A:link, DIV.tabs A:visited, 46 | DIV.tabs A:active, DIV.tabs A:hover 47 | { 48 | color: #1A419D; 49 | } 50 | 51 | DIV.tabs SPAN 52 | { 53 | float : left; 54 | display : block; 55 | background : url("tab_l.gif") no-repeat left top; 56 | padding : 5px 9px; 57 | white-space : nowrap; 58 | } 59 | 60 | DIV.tabs INPUT 61 | { 62 | float : right; 63 | display : inline; 64 | font-size : 1em; 65 | } 66 | 67 | DIV.tabs TD 68 | { 69 | font-size : x-small; 70 | font-weight : bold; 71 | text-decoration : none; 72 | } 73 | 74 | 75 | 76 | /* Commented Backslash Hack hides rule from IE5-Mac \*/ 77 | DIV.tabs SPAN {float : none;} 78 | /* End IE5-Mac hack */ 79 | 80 | DIV.tabs A:hover SPAN 81 | { 82 | background-position: 0% -150px; 83 | } 84 | 85 | DIV.tabs LI#current A 86 | { 87 | background-position: 100% -150px; 88 | border-width : 0px; 89 | } 90 | 91 | DIV.tabs LI#current SPAN 92 | { 93 | background-position: 0% -150px; 94 | padding-bottom : 6px; 95 | } 96 | 97 | DIV.nav 98 | { 99 | background : none; 100 | border : none; 101 | border-bottom : 1px solid #84B0C7; 102 | } 103 | -------------------------------------------------------------------------------- /doc/html/tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | TreeView 8 | 17 | 69 | 70 | 71 | 72 |
73 |

The Protothreads Library 1.3

74 |
75 |

o*The Protothreads Library

76 |

o+File List

77 |
78 |

|o*lc-addrlabels.h

79 |

|o*lc-switch.h

80 |

|o*lc.h

81 |

|o*pt-sem.h

82 |

|\*pt.h

83 |
84 |

o+Data Structures

85 |
86 |

|o*pt

87 |

|\*pt_sem

88 |
89 |

o+Class Hierarchy

90 |
91 |

|o*pt

92 |

|\*pt_sem

93 |
94 |

o*Data Fields

95 |

o+Modules

96 |
97 |

|o+Protothreads

98 | 102 |

|\*Examples

103 |
104 |

\*Globals

105 |
106 |
107 | 108 | 109 | -------------------------------------------------------------------------------- /doc/html/using.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Protothreads Library 1.0: 4 | 5 | 6 | 7 | 8 |
Generated on Thu Feb 24 01:34:15 2005 for The Protothreads Library 1.0 by 9 | 10 | doxygen 11 | 1.3.6
12 | 13 | 14 | -------------------------------------------------------------------------------- /doc/pt-doc.txt: -------------------------------------------------------------------------------- 1 | /** 2 | \defgroup pt Protothreads 3 | @{ 4 | Protothreads are implemented in a single header file, pt.h, which 5 | includes the local continuations header file, lc.h. This file in turn 6 | includes the actual implementation of local continuations, which 7 | typically also is contained in a single header file. 8 | 9 | */ 10 | 11 | /** @} */ 12 | 13 | /** 14 | \defgroup examples Examples 15 | @{ 16 | 17 | \section example-small A small example 18 | 19 | This first example shows a very simple program: two protothreads 20 | waiting for each other to toggle two flags. The code illustrates how 21 | to write protothreads code, how to initialize protothreads, and how to 22 | schedule them. 23 | 24 | \include example-small.c 25 | 26 | 27 | \section example-code-lock A code-lock 28 | This example shows how to implement a simple code lock - the kind of 29 | device that is placed next to doors and that you have to push a four 30 | digit number into in order to unlock the door. 31 | 32 | The code lock waits for key presses from a numeric keyboard and if the 33 | correct code is entered, the lock is unlocked. There is a maximum time 34 | of one second between each key press, and after the correct code has 35 | been entered, no more keys must be pressed for 0.5 seconds before the 36 | lock is opened. 37 | 38 | \include example-codelock.c 39 | 40 | \section example-buffer The bounded buffer with protothread semaphores 41 | 42 | The following example shows how to implement the bounded buffer 43 | problem using the protothreads semaphore library. The example uses 44 | three protothreads: one producer() protothread that produces items, 45 | one consumer() protothread that consumes items, and one 46 | driver_thread() that schedules the producer and consumer protothreads. 47 | 48 | Note that there is no need for a mutex to guard the add_to_buffer() 49 | and get_from_buffer() functions because of the implicit locking 50 | semantics of protothreads - a protothread will never be preempted and 51 | will never block except in an explicit PT_WAIT statement. 52 | 53 | \include example-buffer.c 54 | 55 | */ 56 | 57 | 58 | /** @} */ 59 | -------------------------------------------------------------------------------- /doc/pt-mainpage.txt: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | \mainpage The Protothreads Library 4 | 5 | \author Adam Dunkels 6 | 7 | Protothreads are a type of lightweight stackless threads designed for 8 | severly memory constrained systems such as deeply embedded systems or 9 | sensor network nodes. Protothreads provides linear code execution for 10 | event-driven systems implemented in C. Protothreads can be used with 11 | or without an RTOS. 12 | 13 | Protothreads are a extremely lightweight, stackless type of threads 14 | that provides a blocking context on top of an event-driven system, 15 | without the overhead of per-thread stacks. The purpose of protothreads 16 | is to implement sequential flow of control without complex state 17 | machines or full multi-threading. Protothreads provides conditional 18 | blocking inside C functions. 19 | 20 | Main features: 21 | 22 | - No machine specific code - the protothreads library is pure C 23 | 24 | - Does not use error-prone functions such as longjmp() 25 | 26 | - Very small RAM overhead - only two bytes per protothread 27 | 28 | - Can be used with or without an OS 29 | 30 | - Provides blocking wait without full multi-threading or 31 | stack-switching 32 | 33 | Examples applications: 34 | 35 | - Memory constrained systems 36 | 37 | - Event-driven protocol stacks 38 | 39 | - Deeply embedded systems 40 | 41 | - Sensor network nodes 42 | 43 | 44 | \sa \ref examples "Example programs" 45 | \sa \ref pt "Protothreads API documentation" 46 | 47 | The protothreads library is released under a BSD-style license that 48 | allows for both non-commercial and commercial usage. The only 49 | requirement is that credit is given. 50 | 51 | More information and new version of the code can be found at the 52 | Protothreads homepage: 53 | 54 | http://www.sics.se/~adam/pt/ 55 | 56 | \section authors Authors 57 | 58 | The protothreads library was written by Adam Dunkels 59 | with support from Oliver Schmidt . 60 | 61 | \section using Using protothreads 62 | 63 | Using protothreads in a project is easy: simply copy the files pt.h, 64 | lc.h and lc-switch.h into the include files directory of the project, 65 | and \#include "pt.h" in all files that should use protothreads. 66 | 67 | \section pt-desc Protothreads 68 | 69 | Protothreads are a extremely lightweight, stackless threads that 70 | provides a blocking context on top of an event-driven system, without 71 | the overhead of per-thread stacks. The purpose of protothreads is to 72 | implement sequential flow of control without using complex state 73 | machines or full multi-threading. Protothreads provides conditional 74 | blocking inside a C function. 75 | 76 | In memory constrained systems, such as deeply embedded systems, 77 | traditional multi-threading may have a too large memory overhead. In 78 | traditional multi-threading, each thread requires its own stack, that 79 | typically is over-provisioned. The stacks may use large parts of the 80 | available memory. 81 | 82 | The main advantage of protothreads over ordinary threads is that 83 | protothreads are very lightweight: a protothread does not require its 84 | own stack. Rather, all protothreads run on the same stack and context 85 | switching is done by stack rewinding. This is advantageous in memory 86 | constrained systems, where a stack for a thread might use a large part 87 | of the available memory. A protothread only requires only two bytes of 88 | memory per protothread. Moreover, protothreads are implemented in pure 89 | C and do not require any machine-specific assembler code. 90 | 91 | A protothread runs within a single C function and cannot span over 92 | other functions. A protothread may call normal C functions, but cannot 93 | block inside a called function. Blocking inside nested function calls 94 | is instead made by spawning a separate protothread for each 95 | potentially blocking function. The advantage of this approach is that 96 | blocking is explicit: the programmer knows exactly which functions 97 | that block that which functions the never blocks. 98 | 99 | Protothreads are similar to asymmetric co-routines. The main 100 | difference is that co-routines uses a separate stack for each 101 | co-routine, whereas protothreads are stackless. The most similar 102 | mechanism to protothreads are Python generators. These are also 103 | stackless constructs, but have a different purpose. Protothreads 104 | provides blocking contexts inside a C function, whereas Python 105 | generators provide multiple exit points from a generator function. 106 | 107 | \section pt-autovars Local variables 108 | 109 | \note 110 | Because protothreads do not save the stack context across a blocking 111 | call, local variables are not preserved when the protothread 112 | blocks. This means that local variables should be used with utmost 113 | care - if in doubt, do not use local variables inside a protothread! 114 | 115 | \section pt-scheduling Scheduling 116 | 117 | A protothread is driven by repeated calls to the function in which the 118 | protothread is running. Each time the function is called, the 119 | protothread will run until it blocks or exits. Thus the scheduling of 120 | protothreads is done by the application that uses protothreads. 121 | 122 | \section pt-impl Implementation 123 | 124 | Protothreads are implemented using local continuations. A local 125 | continuation represents the current state of execution at a particular 126 | place in the program, but does not provide any call history or local 127 | variables. A local continuation can be set in a specific function to 128 | capture the state of the function. After a local continuation has been 129 | set can be resumed in order to restore the state of the function at 130 | the point where the local continuation was set. 131 | 132 | 133 | Local continuations can be implemented in a variety of ways: 134 | 135 | -# by using machine specific assembler code, 136 | -# by using standard C constructs, or 137 | -# by using compiler extensions. 138 | 139 | The first way works by saving and restoring the processor state, 140 | except for stack pointers, and requires between 16 and 32 bytes of 141 | memory per protothread. The exact amount of memory required depends on 142 | the architecture. 143 | 144 | The standard C implementation requires only two bytes of state per 145 | protothread and utilizes the C switch() statement in a non-obvious way 146 | that is similar to Duff's device. This implementation does, however, 147 | impose a slight restriction to the code that uses protothreads: a 148 | protothread cannot perform a blocking wait (PT_WAIT_UNTIL() or 149 | PT_YIELD()) inside a switch() statement. 150 | 151 | Certain compilers has C extensions that can be used to implement 152 | protothreads. GCC supports label pointers that can be used for this 153 | purpose. With this implementation, protothreads require 4 bytes of RAM 154 | per protothread. 155 | 156 | */ 157 | -------------------------------------------------------------------------------- /doc/pt-refman.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/pt-refman.pdf -------------------------------------------------------------------------------- /doc/sicslogo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gburd/pt/01c2b4ea78cbd00c542efa2a8ba9cf4307743cec/doc/sicslogo.pdf -------------------------------------------------------------------------------- /example-buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the protothreads library. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: example-buffer.c,v 1.5 2005/10/07 05:21:33 adam Exp $ 34 | */ 35 | 36 | #ifdef _WIN32 37 | #include 38 | #else 39 | #include 40 | #endif 41 | #include 42 | 43 | #include "pt-sem.h" 44 | 45 | #define NUM_ITEMS 32 46 | #define BUFSIZE 8 47 | 48 | static int buffer[BUFSIZE]; 49 | static int bufptr; 50 | 51 | static void 52 | add_to_buffer(int item) 53 | { 54 | printf("Item %d added to buffer at place %d\n", item, bufptr); 55 | buffer[bufptr] = item; 56 | bufptr = (bufptr + 1) % BUFSIZE; 57 | } 58 | static int 59 | get_from_buffer(void) 60 | { 61 | int item; 62 | item = buffer[bufptr]; 63 | printf("Item %d retrieved from buffer at place %d\n", 64 | item, bufptr); 65 | bufptr = (bufptr + 1) % BUFSIZE; 66 | return item; 67 | } 68 | 69 | static int 70 | produce_item(void) 71 | { 72 | static int item = 0; 73 | printf("Item %d produced\n", item); 74 | return item++; 75 | } 76 | 77 | static void 78 | consume_item(int item) 79 | { 80 | printf("Item %d consumed\n", item); 81 | } 82 | 83 | static struct pt_sem full, empty; 84 | 85 | static 86 | PT_THREAD(producer(struct pt *pt)) 87 | { 88 | static int produced; 89 | 90 | PT_BEGIN(pt); 91 | 92 | for(produced = 0; produced < NUM_ITEMS; ++produced) { 93 | 94 | PT_SEM_WAIT(pt, &full); 95 | 96 | add_to_buffer(produce_item()); 97 | 98 | PT_SEM_SIGNAL(pt, &empty); 99 | } 100 | 101 | PT_END(pt); 102 | } 103 | 104 | static 105 | PT_THREAD(consumer(struct pt *pt)) 106 | { 107 | static int consumed; 108 | 109 | PT_BEGIN(pt); 110 | 111 | for(consumed = 0; consumed < NUM_ITEMS; ++consumed) { 112 | 113 | PT_SEM_WAIT(pt, &empty); 114 | 115 | consume_item(get_from_buffer()); 116 | 117 | PT_SEM_SIGNAL(pt, &full); 118 | } 119 | 120 | PT_END(pt); 121 | } 122 | 123 | static 124 | PT_THREAD(driver_thread(struct pt *pt)) 125 | { 126 | static struct pt pt_producer, pt_consumer; 127 | 128 | PT_BEGIN(pt); 129 | 130 | PT_SEM_INIT(&empty, 0); 131 | PT_SEM_INIT(&full, BUFSIZE); 132 | 133 | PT_INIT(&pt_producer); 134 | PT_INIT(&pt_consumer); 135 | 136 | PT_WAIT_THREAD(pt, producer(&pt_producer) & 137 | consumer(&pt_consumer)); 138 | 139 | PT_END(pt); 140 | } 141 | 142 | 143 | int 144 | main(void) 145 | { 146 | struct pt driver_pt; 147 | 148 | PT_INIT(&driver_pt); 149 | 150 | while(PT_SCHEDULE(driver_thread(&driver_pt))) { 151 | 152 | /* 153 | * When running this example on a multitasking system, we must 154 | * give other processes a chance to run too and therefore we call 155 | * usleep() resp. Sleep() here. On a dedicated embedded system, 156 | * we usually do not need to do this. 157 | */ 158 | #ifdef _WIN32 159 | Sleep(0); 160 | #else 161 | usleep(10); 162 | #endif 163 | } 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /example-small.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a very small example that shows how to use 3 | * protothreads. The program consists of two protothreads that wait 4 | * for each other to toggle a variable. 5 | */ 6 | 7 | /* We must always include pt.h in our protothreads code. */ 8 | #include "pt.h" 9 | 10 | #include /* For printf(). */ 11 | 12 | /* Two flags that the two protothread functions use. */ 13 | static int protothread1_flag, protothread2_flag; 14 | 15 | /** 16 | * The first protothread function. A protothread function must always 17 | * return an integer, but must never explicitly return - returning is 18 | * performed inside the protothread statements. 19 | * 20 | * The protothread function is driven by the main loop further down in 21 | * the code. 22 | */ 23 | static int 24 | protothread1(struct pt *pt) 25 | { 26 | /* A protothread function must begin with PT_BEGIN() which takes a 27 | pointer to a struct pt. */ 28 | PT_BEGIN(pt); 29 | 30 | /* We loop forever here. */ 31 | while(1) { 32 | /* Wait until the other protothread has set its flag. */ 33 | PT_WAIT_UNTIL(pt, protothread2_flag != 0); 34 | printf("Protothread 1 running\n"); 35 | 36 | /* We then reset the other protothread's flag, and set our own 37 | flag so that the other protothread can run. */ 38 | protothread2_flag = 0; 39 | protothread1_flag = 1; 40 | 41 | /* And we loop. */ 42 | } 43 | 44 | /* All protothread functions must end with PT_END() which takes a 45 | pointer to a struct pt. */ 46 | PT_END(pt); 47 | } 48 | 49 | /** 50 | * The second protothread function. This is almost the same as the 51 | * first one. 52 | */ 53 | static int 54 | protothread2(struct pt *pt) 55 | { 56 | PT_BEGIN(pt); 57 | 58 | while(1) { 59 | /* Let the other protothread run. */ 60 | protothread2_flag = 1; 61 | 62 | /* Wait until the other protothread has set its flag. */ 63 | PT_WAIT_UNTIL(pt, protothread1_flag != 0); 64 | printf("Protothread 2 running\n"); 65 | 66 | /* We then reset the other protothread's flag. */ 67 | protothread1_flag = 0; 68 | 69 | /* And we loop. */ 70 | } 71 | PT_END(pt); 72 | } 73 | 74 | /** 75 | * Finally, we have the main loop. Here is where the protothreads are 76 | * initialized and scheduled. First, however, we define the 77 | * protothread state variables pt1 and pt2, which hold the state of 78 | * the two protothreads. 79 | */ 80 | static struct pt pt1, pt2; 81 | int 82 | main(void) 83 | { 84 | /* Initialize the protothread state variables with PT_INIT(). */ 85 | PT_INIT(&pt1); 86 | PT_INIT(&pt2); 87 | 88 | /* 89 | * Then we schedule the two protothreads by repeatedly calling their 90 | * protothread functions and passing a pointer to the protothread 91 | * state variables as arguments. 92 | */ 93 | while(1) { 94 | protothread1(&pt1); 95 | protothread2(&pt2); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lc-addrlabels.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: lc-addrlabels.h,v 1.4 2006/06/03 11:29:43 adam Exp $ 34 | */ 35 | 36 | /** 37 | * \addtogroup lc 38 | * @{ 39 | */ 40 | 41 | /** 42 | * \file 43 | * Implementation of local continuations based on the "Labels as 44 | * values" feature of gcc 45 | * \author 46 | * Adam Dunkels 47 | * 48 | * This implementation of local continuations is based on a special 49 | * feature of the GCC C compiler called "labels as values". This 50 | * feature allows assigning pointers with the address of the code 51 | * corresponding to a particular C label. 52 | * 53 | * For more information, see the GCC documentation: 54 | * http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 55 | * 56 | */ 57 | 58 | #ifndef __LC_ADDRLABELS_H__ 59 | #define __LC_ADDRLABELS_H__ 60 | 61 | /** \hideinitializer */ 62 | typedef void * lc_t; 63 | 64 | #define LC_INIT(s) s = NULL 65 | 66 | #define LC_RESUME(s) \ 67 | do { \ 68 | if(s != NULL) { \ 69 | goto *s; \ 70 | } \ 71 | } while(0) 72 | 73 | #define LC_CONCAT2(s1, s2) s1##s2 74 | #define LC_CONCAT(s1, s2) LC_CONCAT2(s1, s2) 75 | 76 | #define LC_SET(s) \ 77 | do { \ 78 | LC_CONCAT(LC_LABEL, __LINE__): \ 79 | (s) = &&LC_CONCAT(LC_LABEL, __LINE__); \ 80 | } while(0) 81 | 82 | #define LC_END(s) 83 | 84 | #endif /* __LC_ADDRLABELS_H__ */ 85 | /** @} */ 86 | -------------------------------------------------------------------------------- /lc-switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the Contiki operating system. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: lc-switch.h,v 1.4 2006/06/03 11:29:43 adam Exp $ 34 | */ 35 | 36 | /** 37 | * \addtogroup lc 38 | * @{ 39 | */ 40 | 41 | /** 42 | * \file 43 | * Implementation of local continuations based on switch() statment 44 | * \author Adam Dunkels 45 | * 46 | * This implementation of local continuations uses the C switch() 47 | * statement to resume execution of a function somewhere inside the 48 | * function's body. The implementation is based on the fact that 49 | * switch() statements are able to jump directly into the bodies of 50 | * control structures such as if() or while() statmenets. 51 | * 52 | * This implementation borrows heavily from Simon Tatham's coroutines 53 | * implementation in C: 54 | * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html 55 | */ 56 | 57 | #ifndef __LC_SWITCH_H__ 58 | #define __LC_SWITCH_H__ 59 | 60 | /* WARNING! lc implementation using switch() does not work if an 61 | LC_SET() is done within another switch() statement! */ 62 | 63 | /** \hideinitializer */ 64 | typedef unsigned short lc_t; 65 | 66 | #define LC_INIT(s) s = 0; 67 | 68 | #define LC_RESUME(s) switch(s) { case 0: 69 | 70 | #define LC_SET(s) s = __LINE__; case __LINE__: 71 | 72 | #define LC_END(s) } 73 | 74 | #endif /* __LC_SWITCH_H__ */ 75 | 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /lc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2005, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the protothreads library. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: lc.h,v 1.2 2005/02/24 10:36:59 adam Exp $ 34 | */ 35 | 36 | /** 37 | * \addtogroup pt 38 | * @{ 39 | */ 40 | 41 | /** 42 | * \defgroup lc Local continuations 43 | * @{ 44 | * 45 | * Local continuations form the basis for implementing protothreads. A 46 | * local continuation can be set in a specific function to 47 | * capture the state of the function. After a local continuation has 48 | * been set can be resumed in order to restore the state of the 49 | * function at the point where the local continuation was set. 50 | * 51 | * 52 | */ 53 | 54 | /** 55 | * \file lc.h 56 | * Local continuations 57 | * \author 58 | * Adam Dunkels 59 | * 60 | */ 61 | 62 | #ifdef DOXYGEN 63 | /** 64 | * Initialize a local continuation. 65 | * 66 | * This operation initializes the local continuation, thereby 67 | * unsetting any previously set continuation state. 68 | * 69 | * \hideinitializer 70 | */ 71 | #define LC_INIT(lc) 72 | 73 | /** 74 | * Set a local continuation. 75 | * 76 | * The set operation saves the state of the function at the point 77 | * where the operation is executed. As far as the set operation is 78 | * concerned, the state of the function does not include the 79 | * call-stack or local (automatic) variables, but only the program 80 | * counter and such CPU registers that needs to be saved. 81 | * 82 | * \hideinitializer 83 | */ 84 | #define LC_SET(lc) 85 | 86 | /** 87 | * Resume a local continuation. 88 | * 89 | * The resume operation resumes a previously set local continuation, thus 90 | * restoring the state in which the function was when the local 91 | * continuation was set. If the local continuation has not been 92 | * previously set, the resume operation does nothing. 93 | * 94 | * \hideinitializer 95 | */ 96 | #define LC_RESUME(lc) 97 | 98 | /** 99 | * Mark the end of local continuation usage. 100 | * 101 | * The end operation signifies that local continuations should not be 102 | * used any more in the function. This operation is not needed for 103 | * most implementations of local continuation, but is required by a 104 | * few implementations. 105 | * 106 | * \hideinitializer 107 | */ 108 | #define LC_END(lc) 109 | 110 | /** 111 | * \var typedef lc_t; 112 | * 113 | * The local continuation type. 114 | * 115 | * \hideinitializer 116 | */ 117 | #endif /* DOXYGEN */ 118 | 119 | #ifndef __LC_H__ 120 | #define __LC_H__ 121 | 122 | 123 | #ifdef LC_INCLUDE 124 | #include LC_INCLUDE 125 | #else 126 | #include "lc-switch.h" 127 | #endif /* LC_INCLUDE */ 128 | 129 | #endif /* __LC_H__ */ 130 | 131 | /** @} */ 132 | /** @} */ 133 | -------------------------------------------------------------------------------- /pt-sem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * This file is part of the protothreads library. 30 | * 31 | * Author: Adam Dunkels 32 | * 33 | * $Id: pt-sem.h,v 1.2 2005/02/24 10:36:59 adam Exp $ 34 | */ 35 | 36 | /** 37 | * \addtogroup pt 38 | * @{ 39 | */ 40 | 41 | /** 42 | * \defgroup ptsem Protothread semaphores 43 | * @{ 44 | * 45 | * This module implements counting semaphores on top of 46 | * protothreads. Semaphores are a synchronization primitive that 47 | * provide two operations: "wait" and "signal". The "wait" operation 48 | * checks the semaphore counter and blocks the thread if the counter 49 | * is zero. The "signal" operation increases the semaphore counter but 50 | * does not block. If another thread has blocked waiting for the 51 | * semaphore that is signalled, the blocked thread will become 52 | * runnable again. 53 | * 54 | * Semaphores can be used to implement other, more structured, 55 | * synchronization primitives such as monitors and message 56 | * queues/bounded buffers (see below). 57 | * 58 | * The following example shows how the producer-consumer problem, also 59 | * known as the bounded buffer problem, can be solved using 60 | * protothreads and semaphores. Notes on the program follow after the 61 | * example. 62 | * 63 | \code 64 | #include "pt-sem.h" 65 | 66 | #define NUM_ITEMS 32 67 | #define BUFSIZE 8 68 | 69 | static struct pt_sem mutex, full, empty; 70 | 71 | PT_THREAD(producer(struct pt *pt)) 72 | { 73 | static int produced; 74 | 75 | PT_BEGIN(pt); 76 | 77 | for(produced = 0; produced < NUM_ITEMS; ++produced) { 78 | 79 | PT_SEM_WAIT(pt, &full); 80 | 81 | PT_SEM_WAIT(pt, &mutex); 82 | add_to_buffer(produce_item()); 83 | PT_SEM_SIGNAL(pt, &mutex); 84 | 85 | PT_SEM_SIGNAL(pt, &empty); 86 | } 87 | 88 | PT_END(pt); 89 | } 90 | 91 | PT_THREAD(consumer(struct pt *pt)) 92 | { 93 | static int consumed; 94 | 95 | PT_BEGIN(pt); 96 | 97 | for(consumed = 0; consumed < NUM_ITEMS; ++consumed) { 98 | 99 | PT_SEM_WAIT(pt, &empty); 100 | 101 | PT_SEM_WAIT(pt, &mutex); 102 | consume_item(get_from_buffer()); 103 | PT_SEM_SIGNAL(pt, &mutex); 104 | 105 | PT_SEM_SIGNAL(pt, &full); 106 | } 107 | 108 | PT_END(pt); 109 | } 110 | 111 | PT_THREAD(driver_thread(struct pt *pt)) 112 | { 113 | static struct pt pt_producer, pt_consumer; 114 | 115 | PT_BEGIN(pt); 116 | 117 | PT_SEM_INIT(&empty, 0); 118 | PT_SEM_INIT(&full, BUFSIZE); 119 | PT_SEM_INIT(&mutex, 1); 120 | 121 | PT_INIT(&pt_producer); 122 | PT_INIT(&pt_consumer); 123 | 124 | PT_WAIT_THREAD(pt, producer(&pt_producer) & 125 | consumer(&pt_consumer)); 126 | 127 | PT_END(pt); 128 | } 129 | \endcode 130 | * 131 | * The program uses three protothreads: one protothread that 132 | * implements the consumer, one thread that implements the producer, 133 | * and one protothread that drives the two other protothreads. The 134 | * program uses three semaphores: "full", "empty" and "mutex". The 135 | * "mutex" semaphore is used to provide mutual exclusion for the 136 | * buffer, the "empty" semaphore is used to block the consumer is the 137 | * buffer is empty, and the "full" semaphore is used to block the 138 | * producer is the buffer is full. 139 | * 140 | * The "driver_thread" holds two protothread state variables, 141 | * "pt_producer" and "pt_consumer". It is important to note that both 142 | * these variables are declared as static. If the static 143 | * keyword is not used, both variables are stored on the stack. Since 144 | * protothreads do not store the stack, these variables may be 145 | * overwritten during a protothread wait operation. Similarly, both 146 | * the "consumer" and "producer" protothreads declare their local 147 | * variables as static, to avoid them being stored on the stack. 148 | * 149 | * 150 | */ 151 | 152 | /** 153 | * \file 154 | * Couting semaphores implemented on protothreads 155 | * \author 156 | * Adam Dunkels 157 | * 158 | */ 159 | 160 | #ifndef __PT_SEM_H__ 161 | #define __PT_SEM_H__ 162 | 163 | #include "pt.h" 164 | 165 | struct pt_sem { 166 | unsigned int count; 167 | }; 168 | 169 | /** 170 | * Initialize a semaphore 171 | * 172 | * This macro initializes a semaphore with a value for the 173 | * counter. Internally, the semaphores use an "unsigned int" to 174 | * represent the counter, and therefore the "count" argument should be 175 | * within range of an unsigned int. 176 | * 177 | * \param s (struct pt_sem *) A pointer to the pt_sem struct 178 | * representing the semaphore 179 | * 180 | * \param c (unsigned int) The initial count of the semaphore. 181 | * \hideinitializer 182 | */ 183 | #define PT_SEM_INIT(s, c) (s)->count = c 184 | 185 | /** 186 | * Wait for a semaphore 187 | * 188 | * This macro carries out the "wait" operation on the semaphore. The 189 | * wait operation causes the protothread to block while the counter is 190 | * zero. When the counter reaches a value larger than zero, the 191 | * protothread will continue. 192 | * 193 | * \param pt (struct pt *) A pointer to the protothread (struct pt) in 194 | * which the operation is executed. 195 | * 196 | * \param s (struct pt_sem *) A pointer to the pt_sem struct 197 | * representing the semaphore 198 | * 199 | * \hideinitializer 200 | */ 201 | #define PT_SEM_WAIT(pt, s) \ 202 | do { \ 203 | PT_WAIT_UNTIL(pt, (s)->count > 0); \ 204 | --(s)->count; \ 205 | } while(0) 206 | 207 | /** 208 | * Signal a semaphore 209 | * 210 | * This macro carries out the "signal" operation on the semaphore. The 211 | * signal operation increments the counter inside the semaphore, which 212 | * eventually will cause waiting protothreads to continue executing. 213 | * 214 | * \param pt (struct pt *) A pointer to the protothread (struct pt) in 215 | * which the operation is executed. 216 | * 217 | * \param s (struct pt_sem *) A pointer to the pt_sem struct 218 | * representing the semaphore 219 | * 220 | * \hideinitializer 221 | */ 222 | #define PT_SEM_SIGNAL(pt, s) ++(s)->count 223 | 224 | #endif /* __PT_SEM_H__ */ 225 | 226 | /** @} */ 227 | /** @} */ 228 | 229 | -------------------------------------------------------------------------------- /pt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2006, Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the Institute nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | * $Id: pt.h,v 1.6 2006/06/03 11:29:43 adam Exp $ 32 | */ 33 | 34 | /** 35 | * \addtogroup pt 36 | * @{ 37 | */ 38 | 39 | /** 40 | * \file 41 | * Protothreads implementation. 42 | * \author 43 | * Adam Dunkels 44 | * 45 | */ 46 | 47 | #ifndef __PT_H__ 48 | #define __PT_H__ 49 | 50 | #include "lc.h" 51 | 52 | struct pt { 53 | lc_t lc; 54 | }; 55 | 56 | #define PT_WAITING 0 57 | #define PT_EXITED 1 58 | #define PT_ENDED 2 59 | #define PT_YIELDED 3 60 | 61 | /** 62 | * \name Initialization 63 | * @{ 64 | */ 65 | 66 | /** 67 | * Initialize a protothread. 68 | * 69 | * Initializes a protothread. Initialization must be done prior to 70 | * starting to execute the protothread. 71 | * 72 | * \param pt A pointer to the protothread control structure. 73 | * 74 | * \sa PT_SPAWN() 75 | * 76 | * \hideinitializer 77 | */ 78 | #define PT_INIT(pt) LC_INIT((pt)->lc) 79 | 80 | /** @} */ 81 | 82 | /** 83 | * \name Declaration and definition 84 | * @{ 85 | */ 86 | 87 | /** 88 | * Declaration of a protothread function. 89 | * 90 | * This macro is used to declare a protothread function. Protothreads 91 | * function should be declared with this macro, but can also be 92 | * declared as regular C functions that return an integer value. 93 | * 94 | * \param name_args The name and arguments of the C function 95 | * implementing the protothread. 96 | * 97 | * \hideinitializer 98 | */ 99 | #define PT_THREAD(name_args) char name_args 100 | 101 | /** 102 | * Declare the start of a protothread inside the C function 103 | * implementing the protothread. 104 | * 105 | * This macro is used to declare the starting point of a 106 | * protothread. It should be placed at the start of the function in 107 | * which the protothread runs. All C statements above the PT_BEGIN() 108 | * invokation will be executed each time the protothread is scheduled. 109 | * 110 | * \param pt A pointer to the protothread control structure. 111 | * 112 | * \hideinitializer 113 | */ 114 | #define PT_BEGIN(pt) { char PT_YIELD_FLAG = 1; LC_RESUME((pt)->lc) 115 | 116 | /** 117 | * Declare the end of a protothread. 118 | * 119 | * This macro is used for declaring that a protothread ends. It must 120 | * always be used together with a matching PT_BEGIN() macro. 121 | * 122 | * \param pt A pointer to the protothread control structure. 123 | * 124 | * \hideinitializer 125 | */ 126 | #define PT_END(pt) LC_END((pt)->lc); PT_YIELD_FLAG = 0; \ 127 | PT_INIT(pt); return PT_ENDED; } 128 | 129 | /** @} */ 130 | 131 | /** 132 | * \name Blocked wait 133 | * @{ 134 | */ 135 | 136 | /** 137 | * Block and wait until condition is true. 138 | * 139 | * This macro blocks the protothread until the specified condition is 140 | * true. 141 | * 142 | * \param pt A pointer to the protothread control structure. 143 | * \param condition The condition. 144 | * 145 | * \hideinitializer 146 | */ 147 | #define PT_WAIT_UNTIL(pt, condition) \ 148 | do { \ 149 | LC_SET((pt)->lc); \ 150 | if(!(condition)) { \ 151 | return PT_WAITING; \ 152 | } \ 153 | } while(0) 154 | 155 | /** 156 | * Block and wait while condition is true. 157 | * 158 | * This function blocks and waits while condition is true. See 159 | * PT_WAIT_UNTIL(). 160 | * 161 | * \param pt A pointer to the protothread control structure. 162 | * \param cond The condition. 163 | * 164 | * \hideinitializer 165 | */ 166 | #define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond)) 167 | 168 | /** @} */ 169 | 170 | /** 171 | * \name Hierarchical protothreads 172 | * @{ 173 | */ 174 | 175 | /** 176 | * Block and wait until a child protothread completes. 177 | * 178 | * This macro schedules a child protothread. The current protothread 179 | * will block until the child protothread completes. 180 | * 181 | * \note The child protothread must be manually initialized with the 182 | * PT_INIT() function before this function is used. 183 | * 184 | * \param pt A pointer to the protothread control structure. 185 | * \param thread The child protothread with arguments 186 | * 187 | * \sa PT_SPAWN() 188 | * 189 | * \hideinitializer 190 | */ 191 | #define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread)) 192 | 193 | /** 194 | * Spawn a child protothread and wait until it exits. 195 | * 196 | * This macro spawns a child protothread and waits until it exits. The 197 | * macro can only be used within a protothread. 198 | * 199 | * \param pt A pointer to the protothread control structure. 200 | * \param child A pointer to the child protothread's control structure. 201 | * \param thread The child protothread with arguments 202 | * 203 | * \hideinitializer 204 | */ 205 | #define PT_SPAWN(pt, child, thread) \ 206 | do { \ 207 | PT_INIT((child)); \ 208 | PT_WAIT_THREAD((pt), (thread)); \ 209 | } while(0) 210 | 211 | /** @} */ 212 | 213 | /** 214 | * \name Exiting and restarting 215 | * @{ 216 | */ 217 | 218 | /** 219 | * Restart the protothread. 220 | * 221 | * This macro will block and cause the running protothread to restart 222 | * its execution at the place of the PT_BEGIN() call. 223 | * 224 | * \param pt A pointer to the protothread control structure. 225 | * 226 | * \hideinitializer 227 | */ 228 | #define PT_RESTART(pt) \ 229 | do { \ 230 | PT_INIT(pt); \ 231 | return PT_WAITING; \ 232 | } while(0) 233 | 234 | /** 235 | * Exit the protothread. 236 | * 237 | * This macro causes the protothread to exit. If the protothread was 238 | * spawned by another protothread, the parent protothread will become 239 | * unblocked and can continue to run. 240 | * 241 | * \param pt A pointer to the protothread control structure. 242 | * 243 | * \hideinitializer 244 | */ 245 | #define PT_EXIT(pt) \ 246 | do { \ 247 | PT_INIT(pt); \ 248 | return PT_EXITED; \ 249 | } while(0) 250 | 251 | /** @} */ 252 | 253 | /** 254 | * \name Calling a protothread 255 | * @{ 256 | */ 257 | 258 | /** 259 | * Schedule a protothread. 260 | * 261 | * This function shedules a protothread. The return value of the 262 | * function is non-zero if the protothread is running or zero if the 263 | * protothread has exited. 264 | * 265 | * \param f The call to the C function implementing the protothread to 266 | * be scheduled 267 | * 268 | * \hideinitializer 269 | */ 270 | #define PT_SCHEDULE(f) ((f) == PT_WAITING) 271 | 272 | /** @} */ 273 | 274 | /** 275 | * \name Yielding from a protothread 276 | * @{ 277 | */ 278 | 279 | /** 280 | * Yield from the current protothread. 281 | * 282 | * This function will yield the protothread, thereby allowing other 283 | * processing to take place in the system. 284 | * 285 | * \param pt A pointer to the protothread control structure. 286 | * 287 | * \hideinitializer 288 | */ 289 | #define PT_YIELD(pt) \ 290 | do { \ 291 | PT_YIELD_FLAG = 0; \ 292 | LC_SET((pt)->lc); \ 293 | if(PT_YIELD_FLAG == 0) { \ 294 | return PT_YIELDED; \ 295 | } \ 296 | } while(0) 297 | 298 | /** 299 | * \brief Yield from the protothread until a condition occurs. 300 | * \param pt A pointer to the protothread control structure. 301 | * \param cond The condition. 302 | * 303 | * This function will yield the protothread, until the 304 | * specified condition evaluates to true. 305 | * 306 | * 307 | * \hideinitializer 308 | */ 309 | #define PT_YIELD_UNTIL(pt, cond) \ 310 | do { \ 311 | PT_YIELD_FLAG = 0; \ 312 | LC_SET((pt)->lc); \ 313 | if((PT_YIELD_FLAG == 0) || !(cond)) { \ 314 | return PT_YIELDED; \ 315 | } \ 316 | } while(0) 317 | 318 | /** @} */ 319 | 320 | #endif /* __PT_H__ */ 321 | 322 | /** @} */ 323 | --------------------------------------------------------------------------------