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 #if defined(VTK_USE_PTHREADS)
32 #include <pthread.h> // Needed for PTHREAD implementation of mutex
33 typedef pthread_mutex_t vtkMutexType;
34 #endif
35 
36 #ifdef VTK_USE_WIN32_THREADS
37 typedef vtkWindowsHANDLE vtkMutexType;
38 #endif
39 
40 #ifndef VTK_USE_PTHREADS
41 #ifndef VTK_USE_WIN32_THREADS
42 typedef int vtkMutexType;
43 #endif
44 #endif
45 
46 // Mutex lock that is not a vtkObject.
47 class VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
48 {
49 public:
50  // left public purposely
52  virtual ~vtkSimpleMutexLock();
53 
54  static vtkSimpleMutexLock *New();
55 
56  void Delete() {delete this;}
57 
61  void Lock( void );
62 
66  void Unlock( void );
67 
68 protected:
71 
72 private:
73  vtkSimpleMutexLock(const vtkSimpleMutexLock& other) = delete;
74  vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs) = delete;
75 };
76 
77 class VTKCOMMONCORE_EXPORT vtkMutexLock : public vtkObject
78 {
79 public:
80  static vtkMutexLock *New();
81 
82  vtkTypeMacro(vtkMutexLock,vtkObject);
83  void PrintSelf(ostream& os, vtkIndent indent) override;
84 
88  void Lock( void );
89 
93  void Unlock( void );
94 
95 protected:
96 
97  friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
98 
101 private:
102  vtkMutexLock(const vtkMutexLock&) = delete;
103  void operator=(const vtkMutexLock&) = delete;
104 };
105 
106 
107 inline void vtkMutexLock::Lock( void )
108 {
109  this->SimpleMutexLock.Lock();
110 }
111 
112 inline void vtkMutexLock::Unlock( void )
113 {
114  this->SimpleMutexLock.Unlock();
115 }
116 
117 #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:112
void Lock(void)
Lock the vtkMutexLock.
void Lock(void)
Lock the vtkMutexLock.
Definition: vtkMutexLock.h:107
vtkMutexType MutexLock
Definition: vtkMutexLock.h:70
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkSimpleMutexLock SimpleMutexLock
Definition: vtkMutexLock.h:99
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:77
int vtkMutexType
Definition: vtkMutexLock.h:42