00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __CCOROUTINE_H
00019 #define __CCOROUTINE_H
00020
00021
00022 #ifdef _WIN32
00023 #define USE_WIN32_FIBERS
00024 #else
00025 #define USE_PORTABLE_COROUTINES
00026 #endif
00027
00028 #include "defs.h"
00029
00030
00031 #ifdef USE_WIN32_FIBERS
00032
00033 #if _MSC_VER==1200
00034 #define _WIN32_WINNT 0x0400
00035 #endif
00036 #include <windows.h>
00037
00038 #undef min
00039 #undef max
00040 #endif
00041
00042 #ifdef USE_PORTABLE_COROUTINES
00043 struct _Task;
00044 #endif
00045
00046
00052 typedef void (*CoroutineFnp)( void * );
00053
00054
00055
00074 class SIM_API cCoroutine
00075 {
00076 protected:
00077 #ifdef USE_WIN32_FIBERS
00078 LPVOID lpFiber;
00079 static LPVOID lpMainFiber;
00080 unsigned stacksize;
00081 #endif
00082 #ifdef USE_PORTABLE_COROUTINES
00083 _Task *task;
00084 #endif
00085
00086 public:
00089
00094 static void init(unsigned total_stack, unsigned main_stack);
00095
00101 static void switchTo(cCoroutine *cor);
00102
00106 static void switchToMain();
00108
00111
00117 bool setup(CoroutineFnp fnp, void *arg, unsigned stack_size);
00118
00122 cCoroutine();
00123
00127 virtual ~cCoroutine();
00129
00132
00147 virtual bool stackOverflow() const;
00148
00152 virtual unsigned stackSize() const;
00153
00162 virtual unsigned stackUsage() const;
00164 };
00165
00166 #endif
00167
00168