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

Common/vtkCriticalSection.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkCriticalSection.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 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 =========================================================================*/
00051 #ifndef __vtkCriticalSection_h
00052 #define __vtkCriticalSection_h
00053 
00054 #include "vtkObject.h"
00055 
00056 //BTX
00057 
00058 #ifdef VTK_USE_SPROC
00059 #include <abi_mutex.h> // Needed for sproc implementation of mutex
00060 typedef abilock_t vtkCritSecType;
00061 #endif
00062 
00063 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00064 #include <pthread.h> // Needed for pthreads implementation of mutex
00065 typedef pthread_mutex_t vtkCritSecType;
00066 #endif
00067 
00068 #ifdef VTK_USE_WIN32_THREADS
00069 #include <winbase.h> // Needed for win32 implementation of mutex
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 // Critical Section object that is not a vtkObject.
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   // What's the point of these (here and in MutexLock)? This class
00106   // is not part of the hierarchy!! -CRV
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 //ETX
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&);  // Not implemented.
00144   void operator=(const vtkCriticalSection&);  // Not implemented.
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