00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00024 #ifndef __vtkMultiThreader_h
00025 #define __vtkMultiThreader_h
00026
00027 #include "vtkObject.h"
00028
00029 #ifdef VTK_USE_SPROC
00030 #include <sys/types.h>
00031 #include <unistd.h>
00032 #endif
00033
00034 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00035 #include <pthread.h>
00036 #include <sys/types.h>
00037 #include <unistd.h>
00038 #endif
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifdef VTK_USE_SPROC
00054 typedef int vtkThreadProcessIDType;
00055 typedef int vtkMultiThreaderIDType;
00056 #endif
00057
00058
00059
00060
00061
00062 #ifdef VTK_USE_PTHREADS
00063 typedef void *(*vtkThreadFunctionType)(void *);
00064 typedef pthread_t vtkThreadProcessIDType;
00065
00066
00067 typedef pthread_t vtkMultiThreaderIDType;
00068 #endif
00069
00070 #ifdef VTK_USE_WIN32_THREADS
00071 typedef vtkWindowsLPTHREAD_START_ROUTINE vtkThreadFunctionType;
00072 typedef vtkWindowsHANDLE vtkThreadProcessIDType;
00073
00074
00075 typedef vtkWindowsDWORD vtkMultiThreaderIDType;
00076 #endif
00077
00078 #if !defined(VTK_USE_PTHREADS) && !defined(VTK_USE_WIN32_THREADS)
00079 typedef void (*vtkThreadFunctionType)(void *);
00080 typedef int vtkThreadProcessIDType;
00081
00082
00083 typedef int vtkMultiThreaderIDType;
00084 #endif
00085
00086
00087 class vtkMutexLock;
00088
00089 class VTK_COMMON_EXPORT vtkMultiThreader : public vtkObject
00090 {
00091 public:
00092 static vtkMultiThreader *New();
00093
00094 vtkTypeRevisionMacro(vtkMultiThreader,vtkObject);
00095 void PrintSelf(ostream& os, vtkIndent indent);
00096
00108
00109 #define ThreadInfoStruct vtkMultiThreader::ThreadInfo
00110 class ThreadInfo
00111 {
00112 public:
00113 int ThreadID;
00114 int NumberOfThreads;
00115 int *ActiveFlag;
00116 vtkMutexLock *ActiveFlagLock;
00117 void *UserData;
00118 };
00119
00120
00122
00125 vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
00126 virtual int GetNumberOfThreads();
00128
00130
00133 static void SetGlobalMaximumNumberOfThreads(int val);
00134 static int GetGlobalMaximumNumberOfThreads();
00136
00138
00141 static void SetGlobalDefaultNumberOfThreads(int val);
00142 static int GetGlobalDefaultNumberOfThreads();
00144
00145
00146
00147
00148
00149
00152 void SingleMethodExecute();
00153
00157 void MultipleMethodExecute();
00158
00163 void SetSingleMethod(vtkThreadFunctionType, void *data );
00164
00167 void SetMultipleMethod( int index, vtkThreadFunctionType, void *data );
00168
00172 int SpawnThread( vtkThreadFunctionType, void *data );
00173
00175 void TerminateThread( int thread_id );
00176
00178 static vtkMultiThreaderIDType GetCurrentThreadID();
00179
00181
00182 static int ThreadsEqual(vtkMultiThreaderIDType t1,
00183 vtkMultiThreaderIDType t2);
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