VTK
dox/Common/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 "vtkObject.h"
00031 
00032 //BTX
00033 
00034 #ifdef VTK_USE_SPROC
00035 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
00036 typedef abilock_t vtkMutexType;
00037 #endif
00038 
00039 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00040 #include <pthread.h> // Needed for PTHREAD implementation of mutex
00041 typedef pthread_mutex_t vtkMutexType;
00042 #endif
00043  
00044 #ifdef VTK_USE_WIN32_THREADS
00045 typedef vtkWindowsHANDLE vtkMutexType;
00046 #endif
00047 
00048 #ifndef VTK_USE_SPROC
00049 #ifndef VTK_USE_PTHREADS
00050 #ifndef VTK_USE_WIN32_THREADS
00051 typedef int vtkMutexType;
00052 #endif
00053 #endif
00054 #endif
00055 
00056 // Mutex lock that is not a vtkObject.
00057 class VTK_COMMON_EXPORT vtkSimpleMutexLock
00058 {
00059 public:
00060   // left public purposely
00061   vtkSimpleMutexLock();
00062   virtual ~vtkSimpleMutexLock();
00063 
00064   static vtkSimpleMutexLock *New();
00065 
00066   void Delete() {delete this;}
00067   
00069   void Lock( void );
00070 
00072   void Unlock( void );
00073 
00074 protected:
00075   friend class vtkSimpleConditionVariable;
00076   vtkMutexType   MutexLock;
00077 };
00078 
00079 //ETX
00080 
00081 class VTK_COMMON_EXPORT vtkMutexLock : public vtkObject
00082 {
00083 public:
00084   static vtkMutexLock *New();
00085 
00086   vtkTypeMacro(vtkMutexLock,vtkObject);
00087   void PrintSelf(ostream& os, vtkIndent indent);
00088   
00090   void Lock( void );
00091 
00093   void Unlock( void );
00094 
00095 protected:
00096   //BTX
00097   friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
00098   //ETX
00099 
00100   vtkSimpleMutexLock   SimpleMutexLock;
00101   vtkMutexLock() {};
00102 private:
00103   vtkMutexLock(const vtkMutexLock&);  // Not implemented.
00104   void operator=(const vtkMutexLock&);  // Not implemented.
00105 };
00106 
00107 
00108 inline void vtkMutexLock::Lock( void )
00109 {
00110   this->SimpleMutexLock.Lock();
00111 }
00112 
00113 inline void vtkMutexLock::Unlock( void )
00114 {
00115   this->SimpleMutexLock.Unlock();
00116 }
00117 
00118 #endif