Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

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-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00036 #ifndef __vtkThreadedController_h
00037 #define __vtkThreadedController_h
00038 
00039 #include "vtkMultiProcessController.h"
00040 #include "vtkCriticalSection.h" // For vtkSimpleCriticalSection
00041 
00042 class vtkMultiThreader;
00043 
00044 class VTK_PARALLEL_EXPORT vtkThreadedController : public vtkMultiProcessController
00045 {
00046 public:
00047   static vtkThreadedController *New();
00048   vtkTypeRevisionMacro(vtkThreadedController,vtkMultiProcessController);
00049   void PrintSelf(ostream& os, vtkIndent indent);
00050 
00052 
00053   virtual void Initialize(int* argc, char*** argv, int)
00054     { this->Initialize(argc, argv); }
00055   virtual void Initialize(int* argc, char*** argv);
00056   virtual void Finalize();
00057   virtual void Finalize(int) {this->Finalize();}
00059 
00061 
00066   vtkGetMacro(LocalProcessId, int);
00068 
00072   virtual void SingleMethodExecute();
00073   
00077   virtual void MultipleMethodExecute();
00078 
00080   virtual void Barrier();
00081 
00084   virtual void CreateOutputWindow();
00085 
00086 protected:
00087   vtkThreadedController();
00088   ~vtkThreadedController();
00089   
00090   void CreateProcessControllers();
00091   
00093   void Start(int threadIdx);
00094 
00095   void ResetControllers();
00096 
00097   static VTK_THREAD_RETURN_TYPE vtkThreadedControllerStart( void *arg );
00098 
00099   // Each Process/Thread has its own controller.
00100   vtkThreadedController** Controllers;
00101 
00102 //BTX
00103 
00104 // Required only for static access to threadId (GetLocalController).
00105 #ifdef VTK_USE_PTHREADS
00106   typedef pthread_t ThreadIdType;
00107 #elif defined VTK_USE_SPROC
00108   typedef pid_t ThreadIdType;
00109 #elif defined VTK_USE_WIN32_THREADS
00110   typedef DWORD ThreadIdType;
00111 #else
00112   typedef int ThreadIdType;
00113 #endif
00114 
00115 //ETX
00116  
00117   // Used in barrier
00118   static vtkSimpleCriticalSection CounterLock;
00119   static int Counter;
00120   static int IsBarrierInProgress;
00121   static void WaitForPreviousBarrierToEnd();
00122   static void BarrierStarted();
00123   static void BarrierEnded();
00124   static void SignalNextThread();
00125   static void InitializeBarrier();
00126   static void WaitForNextThread();
00127 #ifdef VTK_USE_WIN32_THREADS
00128   static HANDLE BarrierEndedEvent;
00129   static HANDLE NextThread;
00130 #else
00131   static vtkSimpleCriticalSection* BarrierLock;
00132   static vtkSimpleCriticalSection* BarrierInProgress;
00133 #endif
00134   
00135   ThreadIdType ThreadId;
00136 
00137   int LastNumberOfProcesses;
00138 
00139   vtkMultiThreader *MultiThreader;
00140   // Used internally to switch between multiple and single method execution.
00141   int MultipleMethodFlag;
00142   
00143   // For static GetGlobalController.  Translates controller for thread0
00144   // to controller for local thread.
00145   vtkMultiProcessController *GetLocalController();
00146 
00147 private:
00148   vtkThreadedController(const vtkThreadedController&);  // Not implemented.
00149   void operator=(const vtkThreadedController&);  // Not implemented.
00150 };
00151 
00152 #endif
00153 
00154