PCMThread.h
Go to the documentation of this file.00001 00002 // 00003 // This source file is a part of ParCompMark 00004 // Parallel Compositing Benchmark Framework 00005 // 00006 // for latest info see http://parcompmark.sourceforge.net 00007 00008 // 00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team 00010 // 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License 00013 // as published by the Free Software Foundation; either version 2 00014 // of the License, or (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00024 00027 00028 #ifndef __PCM_THREAD_H__ 00029 # define __PCM_THREAD_H__ 00030 00031 // 00032 // Inner includes 00033 // 00034 00035 # include "PCMPremeditations.h" 00036 00037 # include "PCMLogger.h" 00038 00039 # include "PCMException.h" 00040 00041 # include "PCMTimer.h" 00042 00043 # include "PCMPointer.h" 00044 00045 // 00046 // Outer includes 00047 // 00048 00049 # include <pthread.h> 00050 00051 # include <sys/time.h> 00052 00053 namespace ParCompMark 00054 { 00055 00060 class Thread 00061 { 00062 00063 // 00064 // Unit test class 00065 // 00066 # ifdef PARCOMPMARK_TEST 00067 friend class ParCompMarkTest::TestThread; 00068 # endif 00069 00070 // 00071 // Typedefs 00072 // 00073 00074 public: 00075 00077 typedef ParCompMark::Pointer < bool, 00078 Mutex > BoolPointer; 00079 00080 // 00081 // Variables 00082 // 00083 00085 00086 00087 protected: 00088 00094 std::string mThreadName; 00095 00101 BoolPointer mWait; 00102 00108 bool mStopRequested; 00109 00115 bool mJoinable; 00116 00122 bool mWaitThread; 00123 00129 pthread_t mThread; 00130 00136 pthread_cond_t mCondition; 00137 00143 pthread_mutex_t mConditionMutex; 00144 00150 bool mRunning; 00151 00157 u32 mCurrentFPS; 00158 00164 u32 mExpectedFPS; 00165 00171 u32 mIterationNumber; 00172 00174 00175 // 00176 // Constructors & destructor 00177 // 00178 00180 00181 00182 public: 00183 00188 Thread(const std::string & name); 00189 00193 virtual ~ Thread(); 00194 00196 00197 // 00198 // Getters & setters 00199 // 00200 00202 00203 00204 public: 00205 00211 const std::string & getThreadName() const; 00212 00218 const Thread::BoolPointer & getWait() const; 00219 00225 const bool & getStopRequested() const; 00226 00232 const bool & getJoinable() const; 00233 00239 const bool & getWaitThread() const; 00240 00246 const bool & getRunning() const; 00247 00253 const u32 & getCurrentFPS() const; 00254 00260 const u32 & getExpectedFPS() const; 00261 00267 const u32 & getIterationNumber() const; 00268 00270 00271 // 00272 // Class methods 00273 // 00274 00276 00277 00278 public: 00279 00283 static void yield(); 00284 00289 static Real getUSTime(); 00290 00291 protected: 00292 00298 static void *entryPoint(void *arg); 00299 00301 00302 // 00303 // Methods 00304 // 00305 00307 00308 00309 public: 00310 00318 virtual void initThread(const u32 & iterationNumber = 0, const u32 & expectedFPS = 00319 0, const bool & joinable = false, const bool & waitThread = false); 00320 00324 virtual void threadInitialize(); 00325 00329 virtual void threadFinalize(); 00330 00334 virtual void startThread(); 00335 00344 virtual void joinThread(); 00345 00349 virtual void shutDownThread(); 00350 00354 virtual void stopThread(); 00355 00359 virtual void go(); 00360 00361 protected: 00362 00366 virtual void thread(); 00367 00372 virtual bool iteration(); 00373 00382 virtual void task(); 00383 00387 virtual void wait(); 00388 00390 00391 }; 00392 00393 // 00394 // Include header implementation 00395 // 00396 00397 # include "PCMThread_impl.h" 00398 00399 } 00400 00401 #endif