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 #define WIN32_LEAN_AND_MEAN
00037 #include <windows.h>
00038
00039 #undef min
00040 #undef max
00041 #endif
00042
00043 #ifdef USE_PORTABLE_COROUTINES
00044 struct _Task;
00045 #endif
00046
00047
00053 typedef void (*CoroutineFnp)( void * );
00054
00055
00056
00075 class SIM_API cCoroutine
00076 {
00077 protected:
00078 #ifdef USE_WIN32_FIBERS
00079 LPVOID lpFiber;
00080 static LPVOID lpMainFiber;
00081 unsigned stacksize;
00082 #endif
00083 #ifdef USE_PORTABLE_COROUTINES
00084 _Task *task;
00085 #endif
00086
00087 public:
00090
00095 static void init(unsigned total_stack, unsigned main_stack);
00096
00102 static void switchTo(cCoroutine *cor);
00103
00107 static void switchToMain();
00109
00112
00118 bool setup(CoroutineFnp fnp, void *arg, unsigned stack_size);
00119
00123 cCoroutine();
00124
00128 virtual ~cCoroutine();
00130
00133
00148 virtual bool stackOverflow() const;
00149
00153 virtual unsigned stackSize() const;
00154
00163 virtual unsigned stackUsage() const;
00165 };
00166
00167 #endif
00168
00169