![]() |
VR-Link API Documentation for HLA Evolved
|
00001 /****************************************************************************** 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 ******************************************************************************/ 00008 #pragma once 00009 00010 #include "vlMachineTypes.h" 00011 #include "vlThreadSysWrapper.h" 00012 #include "vlMutex.h" 00013 00014 #ifdef DtUSE_UTILITIES_NAMESPACE 00015 namespace DtUSE_UTILITIES_NAMESPACE 00016 { 00017 #endif 00018 00019 00020 00023 class DtRunnable; 00024 00028 typedef void (*DtRunnableFunction)(void*,volatile bool*); 00029 00034 class DT_DLL_VLUTIL DtThreadStart 00035 { 00036 public: 00037 DtThreadStart(DtRunnable* runnable); 00038 DtThreadStart(DtRunnableFunction function,void* data); 00039 00041 void execute(volatile bool* stopFlag); 00042 00044 void stop(); 00045 00046 protected: 00047 DtRunnable* myRunnableObject; 00048 DtRunnableFunction myRunnableFunction; 00049 void* myInitializationData; 00050 }; 00051 00055 class DT_DLL_VLUTIL DtThread 00056 { 00057 public: 00058 00060 static DtThreadId GetCurrentThreadHandle(); 00061 00062 public: 00064 DtThread(DtThreadStart*); 00065 00067 virtual ~DtThread(); 00068 00070 virtual DtThreadStatus start(); 00071 00073 DtThreadStatus startInCurrentThread(); 00074 00078 void stop(bool blocking); 00079 00083 bool hasStarted() const; 00084 00087 bool isRunning() const; 00088 00090 DtThreadStatus join() const; 00091 00093 DtThreadHandle threadId() const { return myThreadID; } 00094 00095 void run(); 00096 00097 protected: 00098 00101 bool stopped(); 00102 00104 DtThreadHandle myThreadID; 00105 00106 private: 00108 DtThread(const DtThread& orig); 00109 DtThread& operator=(const DtThread& orig); 00110 00111 private: 00113 volatile bool myTimeToStop; 00114 00116 bool myRunning; 00117 00118 DtThreadStart* myThreadStart; 00121 mutable DtMutex myMutex; 00122 }; 00123 00124 #ifdef DtUSE_UTILITIES_NAMESPACE 00125 } 00126 #endif 00127