vtkMultiThreader.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00036 #ifndef __vtkMultiThreader_h
00037 #define __vtkMultiThreader_h
00038
00039 #include "vtkObject.h"
00040
00041 #ifdef VTK_USE_SPROC
00042 #include <sys/types.h>
00043 #include <unistd.h>
00044 #endif
00045
00046 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00047 #include <pthread.h>
00048 #include <sys/types.h>
00049 #include <unistd.h>
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #ifdef VTK_USE_SPROC
00066 typedef int vtkThreadProcessIDType;
00067 #endif
00068
00069
00070
00071
00072
00073 #ifdef VTK_USE_PTHREADS
00074 typedef void *(*vtkThreadFunctionType)(void *);
00075 typedef pthread_t vtkThreadProcessIDType;
00076
00077
00078 #endif
00079
00080 #ifdef VTK_USE_WIN32_THREADS
00081 typedef LPTHREAD_START_ROUTINE vtkThreadFunctionType;
00082 typedef HANDLE vtkThreadProcessIDType;
00083
00084
00085 #endif
00086
00087 #if !defined(VTK_USE_PTHREADS) && !defined(VTK_USE_WIN32_THREADS)
00088 typedef void (*vtkThreadFunctionType)(void *);
00089 typedef int vtkThreadProcessIDType;
00090
00091
00092 #endif
00093
00094
00095 class vtkMutexLock;
00096
00097 class VTK_COMMON_EXPORT vtkMultiThreader : public vtkObject
00098 {
00099 public:
00100 static vtkMultiThreader *New();
00101
00102 vtkTypeRevisionMacro(vtkMultiThreader,vtkObject);
00103 void PrintSelf(ostream& os, vtkIndent indent);
00104
00116
00117 #define ThreadInfoStruct vtkMultiThreader::ThreadInfo
00118 class ThreadInfo
00119 {
00120 public:
00121 int ThreadID;
00122 int NumberOfThreads;
00123 int *ActiveFlag;
00124 vtkMutexLock *ActiveFlagLock;
00125 void *UserData;
00126 };
00127
00128
00130
00133 vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
00134 virtual int GetNumberOfThreads();
00136
00138
00141 static void SetGlobalMaximumNumberOfThreads(int val);
00142 static int GetGlobalMaximumNumberOfThreads();
00144
00146
00149 static void SetGlobalDefaultNumberOfThreads(int val);
00150 static int GetGlobalDefaultNumberOfThreads();
00152
00153
00154
00155
00156
00157
00160 void SingleMethodExecute();
00161
00165 void MultipleMethodExecute();
00166
00171 void SetSingleMethod(vtkThreadFunctionType, void *data );
00172
00175 void SetMultipleMethod( int index, vtkThreadFunctionType, void *data );
00176
00180 int SpawnThread( vtkThreadFunctionType, void *data );
00181
00183 void TerminateThread( int thread_id );
00184
00185
00186 protected:
00187 vtkMultiThreader();
00188 ~vtkMultiThreader();
00189
00190
00191 int NumberOfThreads;
00192
00193
00194
00195
00196 ThreadInfo ThreadInfoArray[VTK_MAX_THREADS];
00197
00198
00199 vtkThreadFunctionType SingleMethod;
00200 vtkThreadFunctionType MultipleMethod[VTK_MAX_THREADS];
00201
00202
00203
00204 int SpawnedThreadActiveFlag[VTK_MAX_THREADS];
00205 vtkMutexLock *SpawnedThreadActiveFlagLock[VTK_MAX_THREADS];
00206 vtkThreadProcessIDType SpawnedThreadProcessID[VTK_MAX_THREADS];
00207 ThreadInfo SpawnedThreadInfoArray[VTK_MAX_THREADS];
00208
00209
00210
00211
00212 void *SingleData;
00213 void *MultipleData[VTK_MAX_THREADS];
00214
00215 private:
00216 vtkMultiThreader(const vtkMultiThreader&);
00217 void operator=(const vtkMultiThreader&);
00218 };
00219
00220 #endif
00221
00222
00223
00224
00225