00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GXLIB_GXTHREADRUNNER_H
00019 #define GXLIB_GXTHREADRUNNER_H
00020
00021 #include "../gx.h"
00022 #include "gxThreadSafeObject.h"
00023
00028 class gxThreadRunnable
00029 {
00030 public:
00036 virtual void threadMain() = 0;
00037
00042 virtual void onStopThreadRequest() = 0;
00043 };
00044
00045
00056 class gxThread : public gxThreadSafeObject
00057 {
00058 public:
00059
00065 enum priority_t
00066 {
00067 PRIORITY_IDLE,
00068 PRIORITY_LOWEST,
00069 PRIORITY_BELOW_NORMAL,
00070 PRIORITY_NORMAL,
00071 PRIORITY_ABOVE_NORMAL,
00072 PRIORITY_HIGHEST,
00073 PRIORITY_TIME_CRITICAL,
00074 };
00075
00076 enum states_t
00077 {
00078 STATE_STOPPED = 0,
00079 STATE_STARTING = 1,
00080 STATE_STARTED = 2,
00081 STATE_STOPPING = 3
00082 };
00083
00084 gxThread( gxThreadRunnable * runnable, priority_t priority = PRIORITY_NORMAL );
00085
00086 virtual ~gxThread();
00087
00092 void start( bool wait = true );
00093
00099 void stop();
00100
00106 virtual void run();
00107
00115 virtual void onStopThreadRequest();
00116
00120 bool isStopping();
00121
00125 states_t getState();
00126
00130 static void sleep( long milliseconds );
00131
00132 private:
00133 static unsigned int __stdcall threadFunc( void * );
00134 gxThreadRunnable * m_runnable;
00135 unsigned int m_threadid;
00136 void * m_hThread;
00137
00138 states_t m_state;
00139 priority_t m_priority;
00140
00141 void setState( states_t newState );
00142
00143 };
00144 #endif