VTK
|
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 00080 //ETX 00081 00082 class VTKCOMMONCORE_EXPORT vtkMutexLock : public vtkObject 00083 { 00084 public: 00085 static vtkMutexLock *New(); 00086 00087 vtkTypeMacro(vtkMutexLock,vtkObject); 00088 void PrintSelf(ostream& os, vtkIndent indent); 00089 00091 void Lock( void ); 00092 00094 void Unlock( void ); 00095 00096 protected: 00097 //BTX 00098 friend class vtkConditionVariable; // needs to get at SimpleMutexLock. 00099 //ETX 00100 00101 vtkSimpleMutexLock SimpleMutexLock; 00102 vtkMutexLock() {}; 00103 private: 00104 vtkMutexLock(const vtkMutexLock&); // Not implemented. 00105 void operator=(const vtkMutexLock&); // Not implemented. 00106 }; 00107 00108 00109 inline void vtkMutexLock::Lock( void ) 00110 { 00111 this->SimpleMutexLock.Lock(); 00112 } 00113 00114 inline void vtkMutexLock::Unlock( void ) 00115 { 00116 this->SimpleMutexLock.Unlock(); 00117 } 00118 00119 #endif