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

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