Common/vtkCriticalSection.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00051 #ifndef __vtkCriticalSection_h
00052 #define __vtkCriticalSection_h
00053
00054 #include "vtkObject.h"
00055
00056
00057
00058 #ifdef VTK_USE_SPROC
00059 #include <abi_mutex.h>
00060 typedef abilock_t vtkCritSecType;
00061 #endif
00062
00063 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00064 #include <pthread.h>
00065 typedef pthread_mutex_t vtkCritSecType;
00066 #endif
00067
00068 #ifdef VTK_USE_WIN32_THREADS
00069 #include <winbase.h>
00070 typedef CRITICAL_SECTION vtkCritSecType;
00071 #endif
00072
00073 #ifndef VTK_USE_SPROC
00074 #ifndef VTK_USE_PTHREADS
00075 #ifndef VTK_USE_WIN32_THREADS
00076 typedef int vtkCritSecType;
00077 #endif
00078 #endif
00079 #endif
00080
00081
00082 class VTK_COMMON_EXPORT vtkSimpleCriticalSection
00083 {
00084 public:
00085 vtkSimpleCriticalSection()
00086 {
00087 this->Init();
00088 }
00089
00090 vtkSimpleCriticalSection(int isLocked)
00091 {
00092 this->Init();
00093 if(isLocked)
00094 {
00095 this->Lock();
00096 }
00097 }
00098
00099 void Init();
00100
00101 virtual ~vtkSimpleCriticalSection();
00102
00103 static vtkSimpleCriticalSection *New();
00104
00105
00106
00107 virtual const char *GetClassName() {return "vtkSimpleCriticalSection";};
00108 virtual int IsA(const char *name);
00109 static vtkSimpleCriticalSection *SafeDownCast(vtkSimpleCriticalSection *o);
00110
00111 void Delete() {delete this;}
00112
00114 void Lock( void );
00115
00117 void Unlock( void );
00118
00119 protected:
00120 vtkCritSecType CritSec;
00121 };
00122
00123
00124
00125 class VTK_COMMON_EXPORT vtkCriticalSection : public vtkObject
00126 {
00127 public:
00128 static vtkCriticalSection *New();
00129
00130 vtkTypeRevisionMacro(vtkCriticalSection,vtkObject);
00131 void PrintSelf(ostream& os, vtkIndent indent);
00132
00134 void Lock( void );
00135
00137 void Unlock( void );
00138
00139 protected:
00140 vtkSimpleCriticalSection SimpleCriticalSection;
00141 vtkCriticalSection() {};
00142 private:
00143 vtkCriticalSection(const vtkCriticalSection&);
00144 void operator=(const vtkCriticalSection&);
00145 };
00146
00147
00148 inline void vtkCriticalSection::Lock( void )
00149 {
00150 this->SimpleCriticalSection.Lock();
00151 }
00152
00153 inline void vtkCriticalSection::Unlock( void )
00154 {
00155 this->SimpleCriticalSection.Unlock();
00156 }
00157
00158 #endif