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
00060 #ifndef __vtkSharedMemoryCommunicator_h
00061 #define __vtkSharedMemoryCommunicator_h
00062
00063 #include "vtkCommunicator.h"
00064 #include "vtkMultiProcessController.h"
00065 #include "vtkCriticalSection.h"
00066
00067 class vtkThreadedController;
00068 class vtkSharedMemoryCommunicatorMessage;
00069
00070 class VTK_PARALLEL_EXPORT vtkSharedMemoryCommunicator : public vtkCommunicator
00071 {
00072
00073 public:
00074
00075 vtkTypeMacro( vtkSharedMemoryCommunicator,vtkObject);
00076
00078 static vtkSharedMemoryCommunicator* New();
00079
00080 virtual void PrintSelf(ostream& os, vtkIndent indent);
00081
00083
00085 virtual int Send(int* data, int length, int remoteThreadId, int tag);
00086 virtual int Send(unsigned long* data, int length, int remoteThreadId,
00087 int tag);
00088 virtual int Send(char* data, int length, int remoteThreadId, int tag);
00089 virtual int Send(unsigned char* data, int length, int remoteThreadId, int tag);
00090 virtual int Send(float* data, int length, int remoteThreadId, int tag);
00091 virtual int Send(double* data, int length, int remoteThreadId, int tag);
00092 #ifdef VTK_USE_64BIT_IDS
00093 virtual int Send(vtkIdType* data, int length, int remoteThreadId, int tag);
00095 #endif
00096 virtual int Send(vtkDataObject* data, int remoteThreadId, int tag);
00097 virtual int Send(vtkDataArray* data, int remoteThreadId, int tag);
00098
00100
00103 virtual int Receive(int* data, int length, int remoteThreadId,
00104 int tag);
00105 virtual int Receive(unsigned long* data, int length,
00106 int remoteThreadId, int tag);
00107 virtual int Receive(char* data, int length, int remoteThreadId,
00108 int tag);
00109 virtual int Receive(unsigned char* data, int length, int remoteThreadId,
00110 int tag);
00111 virtual int Receive(float* data, int length, int remoteThreadId,
00112 int tag);
00113 virtual int Receive(double* data, int length, int remoteThreadId,
00114 int tag);
00115 #ifdef VTK_USE_64BIT_IDS
00116 virtual int Receive(vtkIdType* data, int length, int remoteThreadId,
00117 int tag);
00119 #endif
00120 virtual int Receive(vtkDataObject *data, int remoteThreadId, int tag);
00121 virtual int Receive(vtkDataArray *data, int remoteThreadId, int tag);
00122
00123
00124
00125 friend class vtkThreadedController;
00126
00127
00128
00129 protected:
00130
00131 int NumberOfThreads;
00132 int Initialized;
00133 void Initialize(int nThreads, int forceDeepCopy);
00134
00135 int LocalThreadId;
00136 int WaitingForId;
00137
00138 int ForceDeepCopy;
00139
00140
00141
00142
00143 vtkSimpleCriticalSection* MessageListLock;
00144
00145
00146
00147 vtkSharedMemoryCommunicator** Communicators;
00148
00149 vtkSharedMemoryCommunicator* Parent;
00150
00151
00152 vtkSharedMemoryCommunicatorMessage *MessageListStart;
00153 vtkSharedMemoryCommunicatorMessage *MessageListEnd;
00154
00155 vtkSharedMemoryCommunicator();
00156 ~vtkSharedMemoryCommunicator();
00157
00158
00159 int Send(vtkDataObject* object, void *data, int dataLength,
00160 int remoteThreadId, int tag);
00161 int Receive(vtkDataObject* object, void *data, int dataLength,
00162 int remoteThreadId, int tag);
00163
00164 int Send(vtkDataArray* object, int dataLength,
00165 int remoteThreadId, int tag);
00166 int Receive(vtkDataArray* object, int dataLength,
00167 int remoteThreadId, int tag);
00168
00169 vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataObject* object,
00170 void* data,
00171 int dataLength);
00172 vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataArray* object,
00173 void* data,
00174 int dataLength);
00175 void DeleteMessage(vtkSharedMemoryCommunicatorMessage *message);
00176 void AddMessage(vtkSharedMemoryCommunicatorMessage *message);
00177 vtkSharedMemoryCommunicatorMessage* FindMessage(int sendId, int tag);
00178
00179 #ifdef _WIN32
00180
00181
00182 HANDLE MessageSignal;
00183 #else
00184
00185
00186 vtkSimpleCriticalSection* Gate;
00187 #endif
00188
00189 void SignalNewMessage(vtkSharedMemoryCommunicator* receiveCommunicator)
00190 {
00191 #ifdef _WIN32
00192 SetEvent( receiveCommunicator->MessageSignal );
00193 #else
00194 receiveCommunicator->Gate->Unlock();
00195 #endif
00196 }
00197
00198 void WaitForNewMessage()
00199 {
00200 #ifdef _WIN32
00201 WaitForSingleObject( this->MessageSignal, INFINITE );
00202 #else
00203 this->Gate->Lock();
00204 #endif
00205 }
00206
00207 private:
00208 vtkSharedMemoryCommunicator(const vtkSharedMemoryCommunicator&);
00209 void operator=(const vtkSharedMemoryCommunicator&);
00210 };
00211
00212 #endif // __vtkSharedMemoryCommunicator_h