00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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