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:
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

Generated on Thu Feb 14 13:30:30 2008 by  doxygen 1.5.1