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:
00059 Coroutine();
00060 virtual ~Coroutine();
00066 void acquire() throw();
00072 void release() throw();
00079 void swapto(Coroutine &o, bool acquired=false);
00080 friend class NewCoroutine;
00081 };
00082
00087 class NewCoroutine : public Coroutine, public RefCounter {
00088 private:
00089 virtual void destroyme();
00090 static void boot();
00091 #ifdef USE_VALGRIND
00092 int valgrind_stackid;
00093 #endif
00094 public:
00100 NewCoroutine(int stacksize=4096*1024);
00101 ~NewCoroutine();
00109 void returnto(Coroutine &o, bool acquired=false);
00114 virtual void start()=0;
00115 };
00116
00117 #endif