Protothreads implementation.
Modified by: Albrecht Weinert <a-weinert.de> Modifications' Copyright (c) 2014 Albrecht Weinert, Bochum
This file is part of the weAutSys runtime system.
The changes Adam Dunkel's original are
1) changing the thread function's return type (centrally) to uint8_t
for GCC C. (It was hard-coded char
.)
2) unconditionally taking lc-adresslabes.h in lc.h for sake of optimised GCC C and tool usage. (It gives a warning on non GCC. In that case change the the implementation of local continuations.)
3) introducing an alias type for the Protothreads (raw) datastructure.
4) a handful of minor improvements and additions
5) extending the (doxygen) comments
Remark: As the Protothreads return types and the (raw) datastructure are intentionally more than lean. A.W. could also hardly resist the temptation to make a pointer to the thread function, a run flag, the current state and else minimal requirements part of struct pt. This would have brought together what belongs together.
But such (semantic) change would have spoiled the documented handling of Protothreads (as e.g. in psocks). So this was not done here. The necessities of weAutSys and akin were implemented in mThr_data_t (in syst_threads.h).
Data Structures | |
struct | pt |
A protothread's (raw) data structure. More... | |
Defines | |
#define | PT_ENDED |
thread has finished | |
#define | PT_EXITED |
thread has finished | |
#define | PT_WAITING 0 |
thread paused due to a condition | |
#define | PT_YIELDED |
Thread paused. | |
#define | ptfnct_t |
The return type of a protothread function. | |
Initialization | |
#define | PT_INIT(pt) |
Initialise a protothread. | |
Declaration and definition | |
#define | PT_BEGIN(pt) |
Declare the start of a protothread inside the protothread function. | |
#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. | |
#define | PT_LEAVE(pt) |
End the 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. | |
#define | PT_YIELD_WHILE(pt, condition) |
Yield while a condition is true. | |
#define | PT_WAIT_ASYIELD_WHILE(pt, condition) |
Wait while a condition is true mimicked as yield. | |
#define | PT_OR_YIELD_HERE(pt) |
Yield only if a previous conditional wait did not. | |
#define | PT_OR_YIELD_REENTER() |
Yield only if a previous conditional wait did not and re-enter that. | |
Typedefs | |
typedef struct pt | pt_t |
A protothread's (raw) data structure as type. |