vtkThreadedController.h

Go to the documentation of this file.
00001 /* $Id: vtkThreadedController.h,v 1.2 2008/09/26 02:46:13 pfb Exp $ */
00002 /*=========================================================================
00003 
00004   Program:   Visualization Toolkit
00005   Module:    $RCSfile: vtkThreadedController.h,v $
00006 
00007   Copyright (c) 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 =========================================================================*/
00016 
00017 /*========================================================================
00018 
00019   This module copied from VTK 4.5 vtkThreadedController.h. There have been no
00020   significant modifications made.
00021 
00022 =========================================================================*/
00023 
00024 #ifndef __vtkThreadedController_h
00025 #define __vtkThreadedController_h
00026 
00031 #include <vtkMultiProcessController.h>
00032 #include <vtkCriticalSection.h>   // For vtkSimpleCriticalSection
00033 
00034 class vtkMultiThreader;
00035 
00050 class VTK_PARALLEL_EXPORT vtkThreadedController : public vtkMultiProcessController
00051   {
00052   /****************************************************************************/
00053                              public:
00054 
00060   static vtkThreadedController *New();
00061 
00062   
00063   vtkTypeRevisionMacro(vtkThreadedController,vtkMultiProcessController);
00064 
00070   void PrintSelf(ostream& os, vtkIndent indent);
00071 
00075   virtual void Initialize(int* argc, char*** argv, int)
00076     { this->Initialize(argc, argv); }
00077   virtual void Initialize(int* argc, char*** argv);
00078   virtual void Finalize();
00079   virtual void Finalize(int) {this->Finalize();}
00080 
00088   vtkGetMacro(LocalProcessId, int);
00089 
00095   virtual void SingleMethodExecute();
00096   
00102   virtual void MultipleMethodExecute();
00103 
00107   virtual void Barrier();
00108 
00114   virtual void CreateOutputWindow();
00115 
00116   /****************************************************************************/
00117                              protected:
00118 
00122   vtkThreadedController();
00123 
00127   ~vtkThreadedController();
00128   
00129   void CreateProcessControllers();
00130   
00135   void Start(int threadIdx);
00136 
00137   void ResetControllers();
00138 
00139   static VTK_THREAD_RETURN_TYPE vtkThreadedControllerStart( void *arg );
00140 
00144   vtkThreadedController** Controllers;
00145 
00146 //BTX
00147 
00148 // Required only for static access to threadId (GetLocalController).
00149 #ifdef VTK_USE_PTHREADS
00150   typedef pthread_t ThreadIdType;
00151 #elif defined VTK_USE_SPROC
00152   typedef pid_t ThreadIdType;
00153 #elif defined VTK_USE_WIN32_THREADS
00154   typedef DWORD ThreadIdType;
00155 #else
00156   typedef int ThreadIdType;
00157 #endif
00158 
00159 //ETX
00160  
00164   static vtkSimpleCriticalSection CounterLock;
00165   static int Counter;
00166   static int IsBarrierInProgress;
00167   static void WaitForPreviousBarrierToEnd();
00168   static void BarrierStarted();
00169   static void BarrierEnded();
00170   static void SignalNextThread();
00171   static void InitializeBarrier();
00172   static void WaitForNextThread();
00173 #ifdef VTK_USE_WIN32_THREADS
00174   static vtkWindowsHANDLE BarrierEndedEvent;
00175   static vtkWindowsHANDLE NextThread;
00176 #else
00177   static vtkSimpleCriticalSection* BarrierLock;
00178   static vtkSimpleCriticalSection* BarrierInProgress;
00179 #endif
00180   
00181   ThreadIdType ThreadId;
00182 
00183   int LastNumberOfProcesses;
00184 
00185   vtkMultiThreader *MultiThreader;
00186   
00190   int MultipleMethodFlag;
00191   
00196   vtkMultiProcessController *GetLocalController();
00197 
00198   /****************************************************************************/
00199                              private:
00200 
00204   vtkThreadedController(const vtkThreadedController&);  // Not implemented.
00205   void operator=(const vtkThreadedController&);  // Not implemented.
00206   };
00207 
00208 /*
00209  * $Log: vtkThreadedController.h,v $
00210  * Revision 1.2  2008/09/26 02:46:13  pfb
00211  * Added note about depreciation.
00212  *
00213  * Revision 1.1  2006/03/22 13:09:31  pfb
00214  * Initial rev.
00215  *
00216  *
00217  */
00218 
00222 #endif
00223 
00224