00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00055 #ifndef __vtkMultiThreader_h
00056 #define __vtkMultiThreader_h
00057
00058 #include "vtkObject.h"
00059 #include "vtkMutexLock.h"
00060
00061 #ifdef VTK_USE_SPROC
00062 #include <sys/types.h>
00063 #include <unistd.h>
00064 #endif
00065
00066 #ifdef VTK_USE_PTHREADS
00067 #include <sys/types.h>
00068 #include <unistd.h>
00069 #endif
00070
00071
00072
00073
00074
00075
00076
00077 #ifdef VTK_USE_SPROC
00078 #define VTK_MAX_THREADS 32
00079 #endif
00080
00081 #ifdef VTK_USE_PTHREADS
00082 #define VTK_MAX_THREADS 32
00083 #endif
00084
00085 #ifdef _WIN32
00086 #define VTK_MAX_THREADS 8
00087 #endif
00088
00089 #ifndef _WIN32
00090 #ifndef VTK_USE_SPROC
00091 #ifndef VTK_USE_PTHREADS
00092 #define VTK_MAX_THREADS 1
00093 #endif
00094 #endif
00095 #endif
00096
00097
00098
00099
00100
00101
00102 #ifdef VTK_USE_SPROC
00103 typedef int vtkThreadProcessIDType;
00104 #endif
00105
00106 #ifdef VTK_USE_PTHREADS
00107 typedef void *(*vtkThreadFunctionType)(void *);
00108 typedef pthread_t vtkThreadProcessIDType;
00109 #define VTK_THREAD_RETURN_VALUE NULL
00110 #define VTK_THREAD_RETURN_TYPE void *
00111 #endif
00112
00113 #ifdef _WIN32
00114 typedef LPTHREAD_START_ROUTINE vtkThreadFunctionType;
00115 typedef HANDLE vtkThreadProcessIDType;
00116 #define VTK_THREAD_RETURN_VALUE 0
00117 #define VTK_THREAD_RETURN_TYPE DWORD __stdcall
00118 #endif
00119
00120 #ifndef _WIN32
00121 #ifndef VTK_USE_PTHREADS
00122 typedef void (*vtkThreadFunctionType)(void *);
00123 typedef int vtkThreadProcessIDType;
00124 #define VTK_THREAD_RETURN_VALUE
00125 #define VTK_THREAD_RETURN_TYPE void
00126 #endif
00127 #endif
00128
00129
00140
00141 struct ThreadInfoStruct
00142 {
00143 int ThreadID;
00144 int NumberOfThreads;
00145 int *ActiveFlag;
00146 vtkMutexLock *ActiveFlagLock;
00147 void *UserData;
00148 };
00149
00150
00151 class VTK_EXPORT vtkMultiThreader : public vtkObject
00152 {
00153 public:
00154 static vtkMultiThreader *New();
00155
00156 vtkTypeMacro(vtkMultiThreader,vtkObject);
00157 void PrintSelf(ostream& os, vtkIndent indent);
00158
00162 vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
00163 vtkGetMacro( NumberOfThreads, int );
00164
00168 static void SetGlobalMaximumNumberOfThreads(int val);
00169 static int GetGlobalMaximumNumberOfThreads();
00170
00174 static void SetGlobalDefaultNumberOfThreads(int val);
00175 static int GetGlobalDefaultNumberOfThreads();
00176
00177
00178
00179
00180
00181
00184 void SingleMethodExecute();
00185
00189 void MultipleMethodExecute();
00190
00195 void SetSingleMethod(vtkThreadFunctionType, void *data );
00196
00199 void SetMultipleMethod( int index, vtkThreadFunctionType, void *data );
00200
00204 int SpawnThread( vtkThreadFunctionType, void *data );
00205
00207 void TerminateThread( int thread_id );
00208
00209
00210 protected:
00211 vtkMultiThreader();
00212 ~vtkMultiThreader();
00213 vtkMultiThreader(const vtkMultiThreader&) {};
00214 void operator=(const vtkMultiThreader&) {};
00215
00216
00217 int NumberOfThreads;
00218
00219
00220
00221
00222 ThreadInfoStruct ThreadInfoArray[VTK_MAX_THREADS];
00223
00224
00225 vtkThreadFunctionType SingleMethod;
00226 vtkThreadFunctionType MultipleMethod[VTK_MAX_THREADS];
00227
00228
00229
00230 int SpawnedThreadActiveFlag[VTK_MAX_THREADS];
00231 vtkMutexLock *SpawnedThreadActiveFlagLock[VTK_MAX_THREADS];
00232 vtkThreadProcessIDType SpawnedThreadProcessID[VTK_MAX_THREADS];
00233 ThreadInfoStruct SpawnedThreadInfoArray[VTK_MAX_THREADS];
00234
00235
00236
00237
00238 void *SingleData;
00239 void *MultipleData[VTK_MAX_THREADS];
00240
00241 };
00242
00243 #endif
00244
00245
00246
00247
00248