00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef LIBMUTH_COROUTINE_DECLS_H
00020 #define LIBMUTH_COROUTINE_DECLS_H
00021
00022 #ifndef __WIN32__
00023 #include <ucontext.h>
00024 #else
00025 #include "win32.h"
00026 #endif
00027 #include "lock.h"
00028 #include "refcounter_decls.h"
00029
00030 class NewCoroutine;
00031
00035 class Coroutine {
00036 private:
00037 Lock running;
00038 Coroutine *from;
00039 bool returned;
00040 int swapcontext(Coroutine&);
00041 int setcontext();
00042 void cleanupfrom();
00043 protected:
00048 ucontext_t context;
00052 virtual void destroyme();
00053 public:
00054 Coroutine();
00055 virtual ~Coroutine();
00061 void acquire();
00068 void swapto(Coroutine &o, bool acquired=false);
00069 friend class NewCoroutine;
00070 };
00071
00076 class NewCoroutine : public Coroutine, public RefCounter {
00077 private:
00078 virtual void destroyme();
00079 static void boot();
00080 #ifdef USE_VALGRIND
00081 int valgrind_stackid;
00082 #endif
00083 public:
00089 NewCoroutine(int stacksize=4096*1024);
00090 ~NewCoroutine();
00098 void returnto(Coroutine &o, bool acquired=false);
00103 virtual void start()=0;
00104 };
00105
00106 #endif