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 =========================================================================*/ 00035 #ifndef __vtkCriticalSection_h 00036 #define __vtkCriticalSection_h 00037 00038 #include "vtkObject.h" 00039 00040 //BTX 00041 00042 #ifdef VTK_USE_SPROC 00043 #include <abi_mutex.h> // Needed for sproc implementation of mutex 00044 typedef abilock_t vtkCritSecType; 00045 #endif 00046 00047 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS) 00048 #include <pthread.h> // Needed for pthreads implementation of mutex 00049 typedef pthread_mutex_t vtkCritSecType; 00050 #endif 00051 00052 #ifdef VTK_USE_WIN32_THREADS 00053 #include <winbase.h> // Needed for win32 implementation of mutex 00054 typedef CRITICAL_SECTION vtkCritSecType; 00055 #endif 00056 00057 #ifndef VTK_USE_SPROC 00058 #ifndef VTK_USE_PTHREADS 00059 #ifndef VTK_USE_WIN32_THREADS 00060 typedef int vtkCritSecType; 00061 #endif 00062 #endif 00063 #endif 00064 00065 // Critical Section object that is not a vtkObject. 00066 class VTK_COMMON_EXPORT vtkSimpleCriticalSection 00067 { 00068 public: 00069 vtkSimpleCriticalSection() 00070 { 00071 this->Init(); 00072 } 00073 00074 vtkSimpleCriticalSection(int isLocked) 00075 { 00076 this->Init(); 00077 if(isLocked) 00078 { 00079 this->Lock(); 00080 } 00081 } 00082 00083 void Init(); 00084 00085 virtual ~vtkSimpleCriticalSection(); 00086 00087 static vtkSimpleCriticalSection *New(); 00088 00089 // What's the point of these (here and in MutexLock)? This class 00090 // is not part of the hierarchy!! -CRV 00091 virtual const char *GetClassName() {return "vtkSimpleCriticalSection";}; 00092 virtual int IsA(const char *name); 00093 static vtkSimpleCriticalSection *SafeDownCast(vtkSimpleCriticalSection *o); 00094 00095 void Delete() {delete this;} 00096 00098 void Lock( void ); 00099 00101 void Unlock( void ); 00102 00103 protected: 00104 vtkCritSecType CritSec; 00105 }; 00106 00107 //ETX 00108 00109 class VTK_COMMON_EXPORT vtkCriticalSection : public vtkObject 00110 { 00111 public: 00112 static vtkCriticalSection *New(); 00113 00114 vtkTypeRevisionMacro(vtkCriticalSection,vtkObject); 00115 void PrintSelf(ostream& os, vtkIndent indent); 00116 00118 void Lock( void ); 00119 00121 void Unlock( void ); 00122 00123 protected: 00124 vtkSimpleCriticalSection SimpleCriticalSection; 00125 vtkCriticalSection() {}; 00126 private: 00127 vtkCriticalSection(const vtkCriticalSection&); // Not implemented. 00128 void operator=(const vtkCriticalSection&); // Not implemented. 00129 }; 00130 00131 00132 inline void vtkCriticalSection::Lock( void ) 00133 { 00134 this->SimpleCriticalSection.Lock(); 00135 } 00136 00137 inline void vtkCriticalSection::Unlock( void ) 00138 { 00139 this->SimpleCriticalSection.Unlock(); 00140 } 00141 00142 #endif