Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef ThreadH
00033 #define ThreadH
00034
00035 #include <zeusbase/System/ZObject.h>
00036 #include <zeusbase/System/Interfaces/IRunnable.hpp>
00037 #include <zeusbase/System/Interfaces/IThread.hpp>
00038
00039 #if defined(ENABLE_LINUX_BINDING)
00040 #include <pthread.h>
00041 #elif defined(ENABLE_WIN32_BINDING)
00042 #if defined(USE_WINDOWS_H)
00043 #include <windows.h>
00044 #endif
00045 #endif
00046
00047
00048 BEGIN_NAMESPACE_Zeus
00049
00050 class TThreadMessageQueue;
00051 class TCriticalSection;
00052 class ISynchronizeObject;
00053
00054
00060
00061 zeusbase_class TThread : public TZObject, public IThread
00062 {
00063 public:
00064
00067
00068 enum EPriority
00069 {
00070 etNormal = 0,
00071 etLow = 1,
00072 etHigh = 2,
00073 etLower = 3,
00074 etHigher = 4,
00075 etTimeCritical = 5
00076 };
00077
00078 TThread(EPriority ePriority = etNormal);
00079 TThread(IRunnable& rObj, EPriority ePriority = etNormal);
00080
00081
00082 EPriority getPriority() const;
00083 void setPriority(EPriority ePriority);
00084 static void sleep(const Float& rfDelay);
00085
00086 virtual void kill(Float64 dTimeOut=0);
00087 virtual bool isAlive() const;
00088 virtual bool isDead() const;
00089 virtual void resume();
00090 virtual bool signalizeStop(Float64 dTimeOut=5.0);
00091 virtual bool start();
00092 virtual void suspend();
00093 virtual bool yield();
00094 virtual Retval postObject(ISynchronizeObject& rObject,
00095 bool bWaitForCompletion);
00096
00097
00098 virtual bool MQUALIFIER isInterrupted() const;
00099 virtual Uint MQUALIFIER getThreadID() const;
00100
00101
00102 MEMORY_MANAGER_DECL
00103
00104 protected:
00106 bool m_bInterrupted;
00108 TThreadMessageQueue& m_rQueue;
00109
00110 virtual ~TThread();
00111 virtual void execute();
00112 virtual void onTerminated() {}
00113 virtual void onStarted() {}
00114
00115 private:
00116 void terminate_internal();
00117 void release_internal();
00118
00120 bool m_bCreated;
00122 bool m_bTerminated;
00124 bool m_bSuspended;
00126 IRunnable* m_pRunObj;
00128 EPriority m_ePriority;
00130 Uint m_uiThreadID;
00131
00132 TCriticalSection& m_rDataLock;
00133
00134
00135 #if defined(ENABLE_LINUX_BINDING)
00136
00137 pthread_t m_Thread;
00138
00139 static void* createThread(void* life);
00140 #elif defined(ENABLE_WIN32_BINDING)
00141
00142 HANDLE m_hHandle;
00143 static Uint32 __stdcall createThread(void* pLife);
00144
00145 #if _WIN32_WINNT >= 0x0400
00146 static void CALLBACK doUserAPCProc(DWORD dwParam);
00147 #endif
00148 #endif
00149 };
00150
00151
00152
00153
00156
00157 inline bool TThread::isAlive() const
00158 {
00159 return !isDead();
00160 }
00161
00162
00168
00169 inline bool TThread::isDead() const
00170 {
00171 return (m_bTerminated || !m_bCreated);
00172 }
00173
00174
00177
00178 inline bool MQUALIFIER TThread::isInterrupted() const
00179 {
00180 return m_bInterrupted;
00181 }
00182
00183
00186
00187 inline TThread::EPriority TThread::getPriority() const
00188 {
00189 return m_ePriority;
00190 }
00191
00192 END_NAMESPACE_Zeus
00193
00194 #endif