![](/media/cache/profiles/c5c2f3677cc6e565cbf176c7f8982c80.jpg.50x50_q85.jpg)
a simple c coroutine for mbed paltform
coroutine.h@0:0177715f0996, 2016-03-06 (annotated)
- Committer:
- mintisan
- Date:
- Sun Mar 06 07:22:27 2016 +0000
- Revision:
- 0:0177715f0996
initial c coroutine for mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mintisan | 0:0177715f0996 | 1 | #ifndef COROUTINE_H_ |
mintisan | 0:0177715f0996 | 2 | #define COROUTINE_H_ |
mintisan | 0:0177715f0996 | 3 | |
mintisan | 0:0177715f0996 | 4 | #ifdef __cplushplus |
mintisan | 0:0177715f0996 | 5 | extern "C"{ |
mintisan | 0:0177715f0996 | 6 | #endif |
mintisan | 0:0177715f0996 | 7 | |
mintisan | 0:0177715f0996 | 8 | /** |
mintisan | 0:0177715f0996 | 9 | * C coroutine |
mintisan | 0:0177715f0996 | 10 | * https://github.com/mintisan/mintisan.github.io/wiki/C#coroutine |
mintisan | 0:0177715f0996 | 11 | */ |
mintisan | 0:0177715f0996 | 12 | |
mintisan | 0:0177715f0996 | 13 | #define cr_start() \ |
mintisan | 0:0177715f0996 | 14 | static int __s = 0; \ |
mintisan | 0:0177715f0996 | 15 | switch(__s){ \ |
mintisan | 0:0177715f0996 | 16 | case 0: |
mintisan | 0:0177715f0996 | 17 | |
mintisan | 0:0177715f0996 | 18 | // '\' doesn't count for one line in C |
mintisan | 0:0177715f0996 | 19 | #define cr_yield(condition) do{ \ |
mintisan | 0:0177715f0996 | 20 | __s = __LINE__ ; \ |
mintisan | 0:0177715f0996 | 21 | case __LINE__: \ |
mintisan | 0:0177715f0996 | 22 | if(condition) \ |
mintisan | 0:0177715f0996 | 23 | return; \ |
mintisan | 0:0177715f0996 | 24 | }while(0) |
mintisan | 0:0177715f0996 | 25 | |
mintisan | 0:0177715f0996 | 26 | #define cr_end() \ |
mintisan | 0:0177715f0996 | 27 | } __s = 0; |
mintisan | 0:0177715f0996 | 28 | |
mintisan | 0:0177715f0996 | 29 | |
mintisan | 0:0177715f0996 | 30 | #ifdef __cplushplus |
mintisan | 0:0177715f0996 | 31 | } |
mintisan | 0:0177715f0996 | 32 | #endif |
mintisan | 0:0177715f0996 | 33 | |
mintisan | 0:0177715f0996 | 34 | #endif |