00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _THREAD_H_
00022 #define _THREAD_H_
00023
00024 #include <boost\thread.hpp>
00025 #include <boost\shared_ptr.hpp>
00026
00027 #include "IThreadCallable.h"
00028
00029 #include "Timer.h"
00030
00031 namespace TestFrameWork
00032 {
00033
00034 class IThreadCallable;
00035
00036 class Thread
00037 {
00038 public:
00039 Thread(IThreadCallablePtr threadCallable, boost::barrier& preSetupBarrier,
00040 boost::barrier& postSetupBarrier, int elapsedTimeSamplesCount = 10);
00041
00042 ~Thread(void);
00043
00044 void operator()(void);
00045
00046 void Join(void);
00047
00048 void Stop(void);
00049
00050 float MeanElapsedTime(void) const;
00051
00052 private:
00053 Timer m_timer;
00054
00055 IThreadCallablePtr m_callable;
00056
00057 bool m_stop;
00058
00059 boost::shared_ptr<boost::thread> m_thread;
00060
00061 bool m_waitForInit;
00062
00063 boost::barrier m_initBarrier;
00064
00065 boost::barrier& m_preSetupBarrier;
00066
00067 boost::barrier& m_postSetupBarrier;
00068 };
00069
00070 typedef boost::shared_ptr<Thread> ThreadPtr;
00071
00072 }
00073
00074 #endif