Thread.hxx
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 #ifndef __THREAD__
00023 #define __THREAD__
00024
00025 #include <pthread.h>
00026 #include "CBL.hxx"
00027 #include "Condition.hxx"
00028
00029
00030
00031 #ifdef Yield
00032 #undef Yield
00033 #endif
00034
00035 namespace CLAM
00036 {
00037 class Condition;
00038
00039 class Thread
00040 {
00041 public:
00042
00043 Thread(bool realtime = false);
00044
00045 virtual ~Thread();
00046
00047 virtual void Start();
00048
00049 virtual void Stop();
00050
00051 void Sleep();
00052
00053 void Sleep( unsigned int milliseconds );
00054
00055 void WakeUp();
00056
00057 void Yield();
00058
00059 void SetThreadCode( const CBL::Functor0& thread_code );
00060
00061 void SetCleanupCode( const CBL::Functor0& cleanup_code );
00062
00063 bool operator==( const Thread& other ) const;
00064
00065 inline bool IsCancelled() const
00066 {
00067 return mIsCancelled;
00068 }
00069
00070 inline bool IsRunning() const
00071 {
00072 return mRunning;
00073 }
00074
00075 protected:
00076 virtual void SetupPriorityPolicy();
00077
00078 bool mRealtime;
00079 bool mHasCode;
00080 bool mHasCleanup;
00081 pthread_t mThreadID;
00082 bool mIsCancelled;
00083 bool mRunning;
00084 CBL::Functor0 mThreadCode;
00085 CBL::Functor0 mCleanUpCode;
00086 Condition mSleepCondition;
00087
00088 private:
00089
00090 void SleepDetail( unsigned int millisecs );
00091
00092
00093
00094 static void* LaunchThread( void* pSelf );
00095
00096 static void LaunchThreadCleanup( void* pSelf );
00097 };
00098
00099 }
00100
00101 #endif // Thread.hxx
00102