a simple c coroutine for mbed paltform

Dependencies:   mbed

Revision:
0:0177715f0996
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coroutine.h	Sun Mar 06 07:22:27 2016 +0000
@@ -0,0 +1,34 @@
+#ifndef COROUTINE_H_
+#define COROUTINE_H_
+
+#ifdef __cplushplus
+extern "C"{
+#endif
+
+/**
+ * C coroutine 
+ * https://github.com/mintisan/mintisan.github.io/wiki/C#coroutine
+ */
+
+#define cr_start()              \
+        static int __s = 0;     \
+        switch(__s){            \
+            case 0:
+
+// '\' doesn't count for one line in C
+#define cr_yield(condition) do{      \
+            __s = __LINE__ ;     \
+                case __LINE__:      \
+                    if(condition)   \
+                    return;         \
+                }while(0)
+
+#define cr_end()                \
+        } __s = 0;            
+
+
+#ifdef __cplushplus
+}
+#endif
+
+#endif