a simple c coroutine for mbed paltform

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers coroutine.h Source File

coroutine.h

00001 #ifndef COROUTINE_H_
00002 #define COROUTINE_H_
00003 
00004 #ifdef __cplushplus
00005 extern "C"{
00006 #endif
00007 
00008 /**
00009  * C coroutine 
00010  * https://github.com/mintisan/mintisan.github.io/wiki/C#coroutine
00011  */
00012 
00013 #define cr_start()              \
00014         static int __s = 0;     \
00015         switch(__s){            \
00016             case 0:
00017 
00018 // '\' doesn't count for one line in C
00019 #define cr_yield(condition) do{      \
00020             __s = __LINE__ ;     \
00021                 case __LINE__:      \
00022                     if(condition)   \
00023                     return;         \
00024                 }while(0)
00025 
00026 #define cr_end()                \
00027         } __s = 0;            
00028 
00029 
00030 #ifdef __cplushplus
00031 }
00032 #endif
00033 
00034 #endif