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

dox/Common/vtkMutexLock.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkMutexLock.h,v $ 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 =========================================================================*/ 00023 #ifndef __vtkMutexVariable_h 00024 #define __vtkMutexVariable_h 00025 00026 00027 #include "vtkObject.h" 00028 00029 //BTX 00030 00031 #ifdef VTK_USE_SPROC 00032 #include <abi_mutex.h> // Needed for SPROC implementation of mutex 00033 typedef abilock_t vtkMutexType; 00034 #endif 00035 00036 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS) 00037 #include <pthread.h> // Needed for PTHREAD implementation of mutex 00038 typedef pthread_mutex_t vtkMutexType; 00039 #endif 00040 00041 #ifdef VTK_USE_WIN32_THREADS 00042 #include <winbase.h> // Needed for WIN32 implementation of mutex 00043 typedef HANDLE vtkMutexType; 00044 #endif 00045 00046 #ifndef VTK_USE_SPROC 00047 #ifndef VTK_USE_PTHREADS 00048 #ifndef VTK_USE_WIN32_THREADS 00049 typedef int vtkMutexType; 00050 #endif 00051 #endif 00052 #endif 00053 00054 // Mutex lock that is not a vtkObject. 00055 class VTK_COMMON_EXPORT vtkSimpleMutexLock 00056 { 00057 public: 00058 // left public purposely 00059 vtkSimpleMutexLock(); 00060 virtual ~vtkSimpleMutexLock(); 00061 00062 static vtkSimpleMutexLock *New(); 00063 00064 virtual const char *GetClassName() {return "vtkSimpleMutexLock";}; 00065 virtual int IsA(const char *name); 00066 static vtkSimpleMutexLock *SafeDownCast(vtkSimpleMutexLock *o); 00067 00068 void Delete() {delete this;} 00069 00071 void Lock( void ); 00072 00074 void Unlock( void ); 00075 00076 protected: 00077 vtkMutexType MutexLock; 00078 }; 00079 00080 //ETX 00081 00082 class VTK_COMMON_EXPORT vtkMutexLock : public vtkObject 00083 { 00084 public: 00085 static vtkMutexLock *New(); 00086 00087 vtkTypeRevisionMacro(vtkMutexLock,vtkObject); 00088 void PrintSelf(ostream& os, vtkIndent indent); 00089 00091 void Lock( void ); 00092 00094 void Unlock( void ); 00095 00096 protected: 00097 vtkSimpleMutexLock SimpleMutexLock; 00098 vtkMutexLock() {}; 00099 private: 00100 vtkMutexLock(const vtkMutexLock&); // Not implemented. 00101 void operator=(const vtkMutexLock&); // Not implemented. 00102 }; 00103 00104 00105 inline void vtkMutexLock::Lock( void ) 00106 { 00107 this->SimpleMutexLock.Lock(); 00108 } 00109 00110 inline void vtkMutexLock::Unlock( void ) 00111 { 00112 this->SimpleMutexLock.Unlock(); 00113 } 00114 00115 #endif