00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00027 #ifndef __vtkMultiThreader_h
00028 #define __vtkMultiThreader_h
00029
00030 #include "vtkObject.h"
00031
00032 #ifdef VTK_USE_SPROC
00033 #include <sys/types.h>
00034 #include <unistd.h>
00035 #endif
00036
00037 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00038 #include <pthread.h>
00039 #include <sys/types.h>
00040 #include <unistd.h>
00041 #endif
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifdef VTK_USE_SPROC
00057 typedef int vtkThreadProcessIDType;
00058 typedef int vtkMultiThreaderIDType;
00059 #endif
00060
00061
00062
00063
00064
00065 #ifdef VTK_USE_PTHREADS
00066 typedef void *(*vtkThreadFunctionType)(void *);
00067 typedef pthread_t vtkThreadProcessIDType;
00068
00069
00070 typedef pthread_t vtkMultiThreaderIDType;
00071 #endif
00072
00073 #ifdef VTK_USE_WIN32_THREADS
00074 typedef vtkWindowsLPTHREAD_START_ROUTINE vtkThreadFunctionType;
00075 typedef vtkWindowsHANDLE vtkThreadProcessIDType;
00076
00077
00078 typedef vtkWindowsDWORD vtkMultiThreaderIDType;
00079 #endif
00080
00081 #if !defined(VTK_USE_PTHREADS) && !defined(VTK_USE_WIN32_THREADS)
00082 typedef void (*vtkThreadFunctionType)(void *);
00083 typedef int vtkThreadProcessIDType;
00084
00085
00086 typedef int vtkMultiThreaderIDType;
00087 #endif
00088
00089
00090 class vtkMutexLock;
00091
00092 class VTK_COMMON_EXPORT vtkMultiThreader : public vtkObject
00093 {
00094 public:
00095 static vtkMultiThreader *New();
00096
00097 vtkTypeMacro(vtkMultiThreader,vtkObject);
00098 void PrintSelf(ostream& os, vtkIndent indent);
00099
00111
00112 #define ThreadInfoStruct vtkMultiThreader::ThreadInfo
00113 class ThreadInfo
00114 {
00115 public:
00116 int ThreadID;
00117 int NumberOfThreads;
00118 int *ActiveFlag;
00119 vtkMutexLock *ActiveFlagLock;
00120 void *UserData;
00121 };
00122
00123
00125
00128 vtkSetClampMacro( NumberOfThreads, int, 1, VTK_MAX_THREADS );
00129 virtual int GetNumberOfThreads();
00131
00133
00136 static void SetGlobalMaximumNumberOfThreads(int val);
00137 static int GetGlobalMaximumNumberOfThreads();
00139
00141
00144 static void SetGlobalDefaultNumberOfThreads(int val);
00145 static int GetGlobalDefaultNumberOfThreads();
00147
00148
00149
00150
00151
00152
00155 void SingleMethodExecute();
00156
00160 void MultipleMethodExecute();
00161
00166 void SetSingleMethod(vtkThreadFunctionType, void *data );
00167
00170 void SetMultipleMethod( int index, vtkThreadFunctionType, void *data );
00171
00175 int SpawnThread( vtkThreadFunctionType, void *data );
00176
00178 void TerminateThread( int thread_id );
00179
00181 int IsThreadActive( int threadID );
00182
00184 static vtkMultiThreaderIDType GetCurrentThreadID();
00185
00187
00188 static int ThreadsEqual(vtkMultiThreaderIDType t1,
00189 vtkMultiThreaderIDType t2);
00191
00192 protected:
00193 vtkMultiThreader();
00194 ~vtkMultiThreader();
00195
00196
00197 int NumberOfThreads;
00198
00199
00200
00201
00202 ThreadInfo ThreadInfoArray[VTK_MAX_THREADS];
00203
00204
00205 vtkThreadFunctionType SingleMethod;
00206 vtkThreadFunctionType MultipleMethod[VTK_MAX_THREADS];
00207
00208
00209
00210 int SpawnedThreadActiveFlag[VTK_MAX_THREADS];
00211 vtkMutexLock *SpawnedThreadActiveFlagLock[VTK_MAX_THREADS];
00212 vtkThreadProcessIDType SpawnedThreadProcessID[VTK_MAX_THREADS];
00213 ThreadInfo SpawnedThreadInfoArray[VTK_MAX_THREADS];
00214
00215
00216
00217
00218 void *SingleData;
00219 void *MultipleData[VTK_MAX_THREADS];
00220
00221 private:
00222 vtkMultiThreader(const vtkMultiThreader&);
00223 void operator=(const vtkMultiThreader&);
00224 };
00225
00226 #endif
00227
00228
00229
00230
00231