VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/Core/vtkMutexLock.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMutexLock.h
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 =========================================================================*/
00026 #ifndef vtkMutexLock_h
00027 #define vtkMutexLock_h
00028 
00029 
00030 #include "vtkCommonCoreModule.h" // For export macro
00031 #include "vtkObject.h"
00032 
00033 //BTX
00034 
00035 #ifdef VTK_USE_SPROC
00036 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
00037 typedef abilock_t vtkMutexType;
00038 #endif
00039 
00040 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00041 #include <pthread.h> // Needed for PTHREAD implementation of mutex
00042 typedef pthread_mutex_t vtkMutexType;
00043 #endif
00044 
00045 #ifdef VTK_USE_WIN32_THREADS
00046 typedef vtkWindowsHANDLE vtkMutexType;
00047 #endif
00048 
00049 #ifndef VTK_USE_SPROC
00050 #ifndef VTK_USE_PTHREADS
00051 #ifndef VTK_USE_WIN32_THREADS
00052 typedef int vtkMutexType;
00053 #endif
00054 #endif
00055 #endif
00056 
00057 // Mutex lock that is not a vtkObject.
00058 class VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
00059 {
00060 public:
00061   // left public purposely
00062   vtkSimpleMutexLock();
00063   virtual ~vtkSimpleMutexLock();
00064 
00065   static vtkSimpleMutexLock *New();
00066 
00067   void Delete() {delete this;}
00068 
00070   void Lock( void );
00071 
00073   void Unlock( void );
00074 
00075 protected:
00076   friend class vtkSimpleConditionVariable;
00077   vtkMutexType   MutexLock;
00078 
00079 private:
00080   vtkSimpleMutexLock(const vtkSimpleMutexLock& other); // no copy constructor
00081   vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs); // no copy assignment
00082 };
00083 
00084 //ETX
00085 
00086 class VTKCOMMONCORE_EXPORT vtkMutexLock : public vtkObject
00087 {
00088 public:
00089   static vtkMutexLock *New();
00090 
00091   vtkTypeMacro(vtkMutexLock,vtkObject);
00092   void PrintSelf(ostream& os, vtkIndent indent);
00093 
00095   void Lock( void );
00096 
00098   void Unlock( void );
00099 
00100 protected:
00101   //BTX
00102   friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
00103   //ETX
00104 
00105   vtkSimpleMutexLock   SimpleMutexLock;
00106   vtkMutexLock() {}
00107 private:
00108   vtkMutexLock(const vtkMutexLock&);  // Not implemented.
00109   void operator=(const vtkMutexLock&);  // Not implemented.
00110 };
00111 
00112 
00113 inline void vtkMutexLock::Lock( void )
00114 {
00115   this->SimpleMutexLock.Lock();
00116 }
00117 
00118 inline void vtkMutexLock::Unlock( void )
00119 {
00120   this->SimpleMutexLock.Unlock();
00121 }
00122 
00123 #endif