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 "vtkWindows.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 void Delete() {delete this;} 00090 00092 void Lock( void ); 00093 00095 void Unlock( void ); 00096 00097 protected: 00098 vtkCritSecType CritSec; 00099 }; 00100 00101 //ETX 00102 00103 class VTK_COMMON_EXPORT vtkCriticalSection : public vtkObject 00104 { 00105 public: 00106 static vtkCriticalSection *New(); 00107 00108 vtkTypeRevisionMacro(vtkCriticalSection,vtkObject); 00109 void PrintSelf(ostream& os, vtkIndent indent); 00110 00112 void Lock( void ); 00113 00115 void Unlock( void ); 00116 00117 protected: 00118 vtkSimpleCriticalSection SimpleCriticalSection; 00119 vtkCriticalSection() {}; 00120 private: 00121 vtkCriticalSection(const vtkCriticalSection&); // Not implemented. 00122 void operator=(const vtkCriticalSection&); // Not implemented. 00123 }; 00124 00125 00126 inline void vtkCriticalSection::Lock( void ) 00127 { 00128 this->SimpleCriticalSection.Lock(); 00129 } 00130 00131 inline void vtkCriticalSection::Unlock( void ) 00132 { 00133 this->SimpleCriticalSection.Unlock(); 00134 } 00135 00136 #endif