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

vtkCriticalSection.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCriticalSection.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00048 #ifndef __vtkCriticalSection_h
00049 #define __vtkCriticalSection_h
00050 
00051 #include "vtkObject.h"
00052 
00053 //BTX
00054 
00055 #ifdef VTK_USE_SPROC
00056 #include <abi_mutex.h> // Needed for sproc implementation of mutex
00057 typedef abilock_t vtkCritSecType;
00058 #endif
00059 
00060 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00061 #include <pthread.h> // Needed for pthreads implementation of mutex
00062 typedef pthread_mutex_t vtkCritSecType;
00063 #endif
00064 
00065 #ifdef VTK_USE_WIN32_THREADS
00066 #include <winbase.h> // Needed for win32 implementation of mutex
00067 typedef CRITICAL_SECTION vtkCritSecType;
00068 #endif
00069 
00070 #ifndef VTK_USE_SPROC
00071 #ifndef VTK_USE_PTHREADS
00072 #ifndef VTK_USE_WIN32_THREADS
00073 typedef int vtkCritSecType;
00074 #endif
00075 #endif
00076 #endif
00077 
00078 // Critical Section object that is not a vtkObject.
00079 class VTK_COMMON_EXPORT vtkSimpleCriticalSection
00080 {
00081 public:
00082   vtkSimpleCriticalSection()
00083     {
00084       this->Init();
00085     }
00086 
00087   vtkSimpleCriticalSection(int isLocked)
00088     {
00089       this->Init();
00090       if(isLocked)
00091         {
00092         this->Lock();
00093         }
00094     }
00095 
00096   void Init();
00097 
00098   virtual ~vtkSimpleCriticalSection();
00099 
00100   static vtkSimpleCriticalSection *New();
00101 
00102   // What's the point of these (here and in MutexLock)? This class
00103   // is not part of the hierarchy!! -CRV
00104   virtual const char *GetClassName() {return "vtkSimpleCriticalSection";};
00105   virtual int IsA(const char *name);
00106   static vtkSimpleCriticalSection *SafeDownCast(vtkSimpleCriticalSection *o);
00107 
00108   void Delete() {delete this;}
00109   
00111   void Lock( void );
00112 
00114   void Unlock( void );
00115 
00116 protected:
00117   vtkCritSecType   CritSec;
00118 };
00119 
00120 //ETX
00121 
00122 class VTK_COMMON_EXPORT vtkCriticalSection : public vtkObject
00123 {
00124 public:
00125   static vtkCriticalSection *New();
00126 
00127   vtkTypeRevisionMacro(vtkCriticalSection,vtkObject);
00128   void PrintSelf(ostream& os, vtkIndent indent);
00129   
00131   void Lock( void );
00132 
00134   void Unlock( void );
00135 
00136 protected:
00137   vtkSimpleCriticalSection   SimpleCriticalSection;
00138   vtkCriticalSection() {};
00139 private:
00140   vtkCriticalSection(const vtkCriticalSection&);  // Not implemented.
00141   void operator=(const vtkCriticalSection&);  // Not implemented.
00142 };
00143 
00144 
00145 inline void vtkCriticalSection::Lock( void )
00146 {
00147   this->SimpleCriticalSection.Lock();
00148 }
00149 
00150 inline void vtkCriticalSection::Unlock( void )
00151 {
00152   this->SimpleCriticalSection.Unlock();
00153 }
00154 
00155 #endif