coroutine_decls.h

00001 /*
00002  *  Copyright (C) 2006  Helmut Grohne
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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

Generated on Sat Feb 7 01:26:50 2009 by  doxygen 1.5.1