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
00052 #ifndef __vtkMultiThreader_h
00053 #define __vtkMultiThreader_h
00054
00055 #include "vtkObject.h"
00056 #include "vtkMutexLock.h"
00057
00058 #ifdef VTK_USE_SPROC
00059 #include <sys/types.h>
00060 #include <unistd.h>
00061 #endif
00062
00063 #ifdef VTK_USE_PTHREADS
00064 #include <sys/types.h>
00065 #include <unistd.h>
00066 #endif
00067
00068
00069
00070
00071
00072
00073
00074 #ifdef VTK_USE_SPROC
00075 #define VTK_MAX_THREADS 32
00076 #endif
00077
00078 #ifdef VTK_USE_PTHREADS
00079 #define VTK_MAX_THREADS 32
00080 #endif
00081
00082
00083 #ifdef VTK_USE_WIN32_THREADS
00084 #define VTK_MAX_THREADS 8
00085 #endif
00086
00087 #ifndef VTK_USE_WIN32_THREADS
00088 #ifndef VTK_USE_SPROC
00089 #ifndef VTK_USE_PTHREADS
00090 #define VTK_MAX_THREADS 1
00091 #endif
00092 #endif
00093 #endif
00094
00095
00096
00097
00098
00099
00100 #ifdef VTK_USE_SPROC
00101 typedef int vtkThreadProcessIDType;
00102 #endif
00103
00104 #ifdef VTK_USE_PTHREADS
00105 typedef void *(*vtkThreadFunctionType)(void *);
00106 typedef pthread_t vtkThreadProcessIDType;
00107 #define VTK_THREAD_RETURN_VALUE NULL
00108 #define VTK_THREAD_RETURN_TYPE void *
00109 #endif
00110
00111 #ifdef VTK_USE_WIN32_THREADS
00112 typedef LPTHREAD_START_ROUTINE vtkThreadFunctionType;
00113 typedef HANDLE vtkThreadProcessIDType;
00114 #define VTK_THREAD_RETURN_VALUE 0
00115 #define VTK_THREAD_RETURN_TYPE DWORD __stdcall
00116 #endif
00117
00118 #if !defined(VTK_USE_PTHREADS) && !defined(VTK_USE_WIN32_THREADS)
00119 typedef void (*vtkThreadFunctionType)(void *);
00120 typedef int vtkThreadProcessIDType;
00121 #define VTK_THREAD_RETURN_VALUE
00122 #define VTK_THREAD_RETURN_TYPE void
00123 #endif
00124
00125
00136
00137 struct ThreadInfoStruct
00138 {
00139 int ThreadID;
00140 int NumberOfThreads;
00141 int *ActiveFlag;
00142 vtkMutexLock *ActiveFlagLock;
00143 void *UserData;
00144 };
00145
00146
00147 class VTK_COMMON_EXPORT vtkMultiThreader : public vtkObject
00148 {
00149 public:
00150 static vtkMultiThreader *New();
00151
00152 vtkTypeMacro(vtkMultiThreader,vtkObject);
00153 void PrintSelf(ostream& os, vtkIndent indent);
00154
00156
00159 vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
00160 vtkGetMacro( NumberOfThreads, int );
00162
00164
00167 static void SetGlobalMaximumNumberOfThreads(int val);
00168 static int GetGlobalMaximumNumberOfThreads();
00170
00172
00175 static void SetGlobalDefaultNumberOfThreads(int val);
00176 static int GetGlobalDefaultNumberOfThreads();
00178
00179
00180
00181
00182
00183
00186 void SingleMethodExecute();
00187
00191 void MultipleMethodExecute();
00192
00197 void SetSingleMethod(vtkThreadFunctionType, void *data );
00198
00201 void SetMultipleMethod( int index, vtkThreadFunctionType, void *data );
00202
00206 int SpawnThread( vtkThreadFunctionType, void *data );
00207
00209 void TerminateThread( int thread_id );
00210
00211
00212 protected:
00213 vtkMultiThreader();
00214 ~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 private:
00242 vtkMultiThreader(const vtkMultiThreader&);
00243 void operator=(const vtkMultiThreader&);
00244 };
00245
00246 #endif
00247
00248
00249
00250
00251