Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

contrib/vtkThreadedController.h

Go to the documentation of this file.
00001 /*=========================================================================
00002   
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkThreadedController.h,v $
00005   Language:  C++
00006   
00007 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00008 All rights reserved.
00009 
00010 Redistribution and use in source and binary forms, with or without
00011 modification, are permitted provided that the following conditions are met:
00012 
00013  * Redistributions of source code must retain the above copyright notice,
00014    this list of conditions and the following disclaimer.
00015 
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019 
00020  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00021    of any contributors may be used to endorse or promote products derived
00022    from this software without specific prior written permission.
00023 
00024  * Modified source versions must be plainly marked as such, and must not be
00025    misrepresented as being the original software.
00026 
00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00033 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00035 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 
00038 =========================================================================*/
00061 #ifndef __vtkThreadedController_h
00062 #define __vtkThreadedController_h
00063 
00064 #include "vtkObject.h"
00065 #include "vtkMultiProcessController.h"
00066 #include "vtkMultiThreader.h"
00067 
00068 
00069 class vtkThreadedControllerMessage;
00070 
00071 
00072 class VTK_EXPORT vtkThreadedController : public vtkMultiProcessController
00073 {
00074 public:
00075   static vtkThreadedController *New();
00076   vtkTypeMacro(vtkThreadedController,vtkMultiProcessController);
00077   void PrintSelf(ostream& os, vtkIndent indent);
00078 
00080   void Initialize(int argc, char *arcv[]);
00081 
00087   vtkGetMacro(LocalProcessId, int);
00088 
00092   void SingleMethodExecute();
00093   
00097   void MultipleMethodExecute();
00098     
00099   //------------------ Communication --------------------
00100   
00103   int Send(vtkDataObject *data, int remoteProcessId, int tag);
00104   int Send(int *data, int length, int remoteProcessId, int tag);
00105   int Send(unsigned long *data, int length, int remoteProcessId, int tag);
00106   int Send(char *data, int length, int remoteProcessId, int tag);
00107   int Send(float *data, int length, int remoteProcessId, int tag);
00108 
00111   int Receive(vtkDataObject *data, int remoteProcessId, int tag);
00112   int Receive(int *data, int length, int remoteProcessId, int tag);
00113   int Receive(unsigned long *data, int length, int remoteProcessId, int tag);
00114   int Receive(char *data, int length, int remoteProcessId, int tag);
00115   int Receive(float *data, int length, int remoteProcessId, int tag);
00116   
00120   void Start(int threadIdx);
00121 
00122 protected:
00123   vtkThreadedController();
00124   ~vtkThreadedController();
00125   vtkThreadedController(const vtkThreadedController&) {};
00126   void operator=(const vtkThreadedController&) {};
00127   
00128   void CreateProcessControllers();
00129   vtkThreadedControllerMessage *NewMessage(vtkDataObject *object,
00130                                            void *data, int dataLength);
00131   void DeleteMessage(vtkThreadedControllerMessage *message);
00132   void AddMessage(vtkThreadedControllerMessage *message);
00133   vtkThreadedControllerMessage *FindMessage(int sendId, int tag);
00134 
00135   // Each Process/Thread has its own controller.
00136   vtkThreadedController *Controllers[VTK_MP_CONTROLLER_MAX_PROCESSES];
00137 
00138   // Required only for static access to threadId (GetLocalController).
00139 #ifdef VTK_USE_PTHREADS
00140   pthread_t ThreadIds[VTK_MP_CONTROLLER_MAX_PROCESSES];
00141 #endif
00142 #ifdef VTK_USE_SPROC
00143   pid_t ThreadIds[VTK_MP_CONTROLLER_MAX_PROCESSES];  
00144 #endif  
00145   
00146   // The id for this objects process.
00147   int LocalProcessId;
00148   int WaitingForId;
00149 
00150   vtkMultiThreader *MultiThreader;
00151   // Used internally to switch between multiple and single method execution.
00152   int MultipleMethodFlag;
00153   
00154   // It is not enough to block on the messages, we have to mutex 
00155   // the whole send interaction.  I was trying to avoid a central 
00156   // mutex (oh well).
00157   vtkMutexLock *MessageListLock;
00158 
00159   // This mutex is normally locked.  It is used to block the execution 
00160   // of the receiving process when the send has not been called yet.
00161   vtkMutexLock *Gate;
00162 
00163   // Double linked list.
00164   vtkThreadedControllerMessage *MessageListStart;
00165   vtkThreadedControllerMessage *MessageListEnd;
00166   
00167   // Trying to track down lockups.
00168   FILE *LogFile;
00169   
00170 
00171   // The generic send and receive methods.
00172   int Send(vtkDataObject *object, void *data, int dataLength, 
00173       int remoteProcessId, int tag);
00174   int Receive(vtkDataObject *object, void *data, int dataLength, 
00175          int remoteProcessId, int tag);
00176 
00177   // For static GetGlobalController.  Translates controller for thread0
00178   // to controller for local thread.
00179   vtkMultiProcessController *GetLocalController();
00180   
00181 };
00182 
00183 
00184 #endif
00185 
00186 

Generated on Wed Nov 21 12:26:56 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001