basicthread.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2005 by Tobias Nadler                                         */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
00019 /*                                                                              */
00020 /********************************************************************************/
00021 
00022 #ifndef BASICTHREAD_H
00023 #define BASICTHREAD_H
00024 
00025 #include "SDL/SDL.h"
00026 #include "SDL/SDL_thread.h"
00027 
00028 #include "basiclog.h"
00029 
00047 class DECLSPEC BasicThread : public BasicLog
00048 {
00049 public:
00055     DECLSPEC BasicThread( TiXmlElement *el, BasicObject *p );
00061     DECLSPEC BasicThread( const char *name, BasicObject *p, const char * fndebug );
00067     DECLSPEC BasicThread( const char *name, BasicObject *p, std::ostream *strm = &std::cout );
00068     virtual DECLSPEC ~BasicThread();
00069 
00070     virtual const char *getClassName()  { return "BasicThread"; }
00071     
00077     DECLSPEC bool start( bool paused = false );
00078     
00084     DECLSPEC void kill();
00085     
00089     DECLSPEC void restart( Uint32 wait = 20 );
00090     
00094     bool running()  { return pThread != 0; }
00095 
00104     DECLSPEC bool lock( Uint32 wait = 0 );
00112     DECLSPEC bool unlock();
00113 
00119     DECLSPEC bool setPause( bool pause );
00120     
00127     DECLSPEC void stop( Uint32 wait = 20 );
00128     
00132     virtual unsigned int getTimePerCycle()  { return tPerCycle; }
00133     
00137     virtual DECLSPEC unsigned int getAvgTimePerCycle();
00142     unsigned int numCycles()    { return nCycles; }
00143 
00144 protected:
00149     virtual int onRun();
00150     
00156     virtual void onCycle()  {}
00157 
00161     Uint32 ulThreadId;
00166     SDL_mutex *mutex;
00167 
00168 private:
00169     bool bStopping, bPaused;
00170     unsigned int tPerCycle, tLastCycle, nCycles, tStart, tPaused;
00171 
00172     SDL_Thread *pThread;
00173     static int startThread( void * pvData );
00174 };
00175 
00176 #endif

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1