Common/vtkCriticalSection.h Source File

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