VTK
vtkMutexLock.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMutexLock.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
24 #ifndef vtkMutexLock_h
25 #define vtkMutexLock_h
26 
27 
28 #include "vtkCommonCoreModule.h" // For export macro
29 #include "vtkObject.h"
30 
31 #ifdef VTK_USE_SPROC
32 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
33 typedef abilock_t vtkMutexType;
34 #endif
35 
36 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
37 #include <pthread.h> // Needed for PTHREAD implementation of mutex
38 typedef pthread_mutex_t vtkMutexType;
39 #endif
40 
41 #ifdef VTK_USE_WIN32_THREADS
42 typedef vtkWindowsHANDLE vtkMutexType;
43 #endif
44 
45 #ifndef VTK_USE_SPROC
46 #ifndef VTK_USE_PTHREADS
47 #ifndef VTK_USE_WIN32_THREADS
48 typedef int vtkMutexType;
49 #endif
50 #endif
51 #endif
52 
53 // Mutex lock that is not a vtkObject.
54 class VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
55 {
56 public:
57  // left public purposely
59  virtual ~vtkSimpleMutexLock();
60 
61  static vtkSimpleMutexLock *New();
62 
63  void Delete() {delete this;}
64 
68  void Lock( void );
69 
73  void Unlock( void );
74 
75 protected:
78 
79 private:
80  vtkSimpleMutexLock(const vtkSimpleMutexLock& other) VTK_DELETE_FUNCTION;
81  vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs) VTK_DELETE_FUNCTION;
82 };
83 
84 class VTKCOMMONCORE_EXPORT vtkMutexLock : public vtkObject
85 {
86 public:
87  static vtkMutexLock *New();
88 
89  vtkTypeMacro(vtkMutexLock,vtkObject);
90  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
91 
95  void Lock( void );
96 
100  void Unlock( void );
101 
102 protected:
103 
104  friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
105 
108 private:
109  vtkMutexLock(const vtkMutexLock&) VTK_DELETE_FUNCTION;
110  void operator=(const vtkMutexLock&) VTK_DELETE_FUNCTION;
111 };
112 
113 
114 inline void vtkMutexLock::Lock( void )
115 {
116  this->SimpleMutexLock.Lock();
117 }
118 
119 inline void vtkMutexLock::Unlock( void )
120 {
121  this->SimpleMutexLock.Unlock();
122 }
123 
124 #endif
mutual exclusion locking class
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Unlock(void)
Unlock the vtkMutexLock.
Definition: vtkMutexLock.h:119
void Lock(void)
Lock the vtkMutexLock.
void Lock(void)
Lock the vtkMutexLock.
Definition: vtkMutexLock.h:114
vtkMutexType MutexLock
Definition: vtkMutexLock.h:77
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkSimpleMutexLock SimpleMutexLock
Definition: vtkMutexLock.h:106
void Unlock(void)
Unlock the vtkMutexLock.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
mutual exclusion locking class
Definition: vtkMutexLock.h:84
int vtkMutexType
Definition: vtkMutexLock.h:48