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

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 =========================================================================*/
00037 #ifndef __vtkMutexVariable_h
00038 #define __vtkMutexVariable_h
00039 
00040 
00041 #include "vtkObject.h"
00042 
00043 //BTX
00044 
00045 #ifdef VTK_USE_SPROC
00046 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
00047 typedef abilock_t vtkMutexType;
00048 #endif
00049 
00050 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
00051 #include <pthread.h> // Needed for PTHREAD implementation of mutex
00052 typedef pthread_mutex_t vtkMutexType;
00053 #endif
00054  
00055 #ifdef VTK_USE_WIN32_THREADS
00056 #include <winbase.h> // Needed for WIN32 implementation of mutex
00057 typedef HANDLE vtkMutexType;
00058 #endif
00059 
00060 #ifndef VTK_USE_SPROC
00061 #ifndef VTK_USE_PTHREADS
00062 #ifndef VTK_USE_WIN32_THREADS
00063 typedef int vtkMutexType;
00064 #endif
00065 #endif
00066 #endif
00067 
00068 // Mutex lock that is not a vtkObject.
00069 class VTK_COMMON_EXPORT vtkSimpleMutexLock
00070 {
00071 public:
00072   // left public purposely
00073   vtkSimpleMutexLock();
00074   virtual ~vtkSimpleMutexLock();
00075 
00076   static vtkSimpleMutexLock *New();
00077 
00078   virtual const char *GetClassName() {return "vtkSimpleMutexLock";};
00079   virtual int IsA(const char *name);
00080   static vtkSimpleMutexLock *SafeDownCast(vtkSimpleMutexLock *o);
00081 
00082   void Delete() {delete this;}
00083   
00085   void Lock( void );
00086 
00088   void Unlock( void );
00089 
00090 protected:
00091   vtkMutexType   MutexLock;
00092 };
00093 
00094 //ETX
00095 
00096 class VTK_COMMON_EXPORT vtkMutexLock : public vtkObject
00097 {
00098 public:
00099   static vtkMutexLock *New();
00100 
00101   vtkTypeRevisionMacro(vtkMutexLock,vtkObject);
00102   void PrintSelf(ostream& os, vtkIndent indent);
00103   
00105   void Lock( void );
00106 
00108   void Unlock( void );
00109 
00110 protected:
00111   vtkSimpleMutexLock   SimpleMutexLock;
00112   vtkMutexLock() {};
00113 private:
00114   vtkMutexLock(const vtkMutexLock&);  // Not implemented.
00115   void operator=(const vtkMutexLock&);  // Not implemented.
00116 };
00117 
00118 
00119 inline void vtkMutexLock::Lock( void )
00120 {
00121   this->SimpleMutexLock.Lock();
00122 }
00123 
00124 inline void vtkMutexLock::Unlock( void )
00125 {
00126   this->SimpleMutexLock.Unlock();
00127 }
00128 
00129 #endif