librfn
An ad-hoc utility library
|
Cooperative multi-tasking without context switching. More...
Macros | |
#define | PT_INIT(pt) |
#define | PT_BEGIN(pt) |
#define | PT_END() |
#define | PT_WAIT() |
#define | PT_WAIT_UNTIL(c) |
#define | PT_YIELD() |
#define | PT_EXIT() return PT_EXITED |
#define | PT_EXIT_ON(x) |
Conditional exit. More... | |
#define | PT_SPAWN(child, thread) |
Call a child thread. More... | |
#define | PT_CALL(child, thread) |
Call a child thread synchronously. More... | |
Typedefs | |
typedef uint16_t | pt_t |
Enumerations | |
enum | pt_state_t { PT_YIELDED, PT_WAITING, PT_EXITED } |
Cooperative multi-tasking without context switching.
Protothreads rely on the normal function call mechanism to switch contexts, however macros provides by the protothread implementation result in execution continuing from the point the thread yielded the processor.
This very simple example does not require a scheduler. Instead the blink function can be called from a polling loop (or systick interrupt) along with all system activity.
Like all protothread implementations this work is inspired by the paper "Protothreads: Simplifying Event-Driven Programming of Memory-Constrained Embedded Systems" by Dunkels et al.
This implementation uses a similar interface as that proposed by Dunkels et al but with sufficient changes to make them incompatible:
#define PT_BEGIN | ( | pt | ) |
Definition at line 93 of file protothreads.h.
#define PT_CALL | ( | child, | |
thread | |||
) |
Call a child thread synchronously.
Run a protothread without ever yielding. This macro is intended to allow protothread library code to be executed in a non-protothreaded environment (for example during initialization routines).
Definition at line 167 of file protothreads.h.
#define PT_END | ( | ) |
Definition at line 100 of file protothreads.h.
#define PT_EXIT | ( | ) | return PT_EXITED |
Definition at line 132 of file protothreads.h.
#define PT_EXIT_ON | ( | x | ) |
Conditional exit.
Mostly used to simplify error paths.
Definition at line 140 of file protothreads.h.
#define PT_INIT | ( | pt | ) |
Definition at line 88 of file protothreads.h.
#define PT_SPAWN | ( | child, | |
thread | |||
) |
Call a child thread.
Definition at line 149 of file protothreads.h.
#define PT_WAIT | ( | ) |
Definition at line 108 of file protothreads.h.
#define PT_WAIT_UNTIL | ( | c | ) |
Definition at line 116 of file protothreads.h.
#define PT_YIELD | ( | ) |
Definition at line 124 of file protothreads.h.
typedef uint16_t pt_t |
Definition at line 86 of file protothreads.h.
enum pt_state_t |
Enumerator | |
---|---|
PT_YIELDED | |
PT_WAITING | |
PT_EXITED |
Definition at line 80 of file protothreads.h.