VTK  9.1.0
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 #include "vtkCommonCoreModule.h" // For export macro
28 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
29 #include "vtkObject.h"
30 #include "vtkThreads.h" // for VTK_USE_PTHREADS and VTK_USE_WIN32_THREADS
31 
32 #if defined(VTK_USE_PTHREADS)
33 #include <pthread.h> // Needed for PTHREAD implementation of mutex
34 typedef pthread_mutex_t vtkMutexType;
35 #endif
36 
37 #ifdef VTK_USE_WIN32_THREADS
38 typedef vtkWindowsHANDLE vtkMutexType;
39 #endif
40 
41 #ifndef VTK_USE_PTHREADS
42 #ifndef VTK_USE_WIN32_THREADS
43 typedef int vtkMutexType;
44 #endif
45 #endif
46 
47 // Mutex lock that is not a vtkObject.
48 
49 class VTK_DEPRECATED_IN_9_1_0("Use std::mutex instead.") VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
50 {
51 public:
52  // left public purposely
55 
57 
58  void Delete() { delete this; }
59 
63  void Lock(void);
64 
68  void Unlock(void);
69 
70 protected:
73 
74 private:
75  vtkSimpleMutexLock(const vtkSimpleMutexLock& other) = delete;
76  vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs) = delete;
77 };
78 
79 class VTK_DEPRECATED_IN_9_1_0("Use std::mutex instead.") VTKCOMMONCORE_EXPORT vtkMutexLock
80  : public vtkObject
81 {
82 public:
83  static vtkMutexLock* New();
84 
85  vtkTypeMacro(vtkMutexLock, vtkObject);
86  void PrintSelf(ostream& os, vtkIndent indent) override;
87 
91  void Lock(void);
92 
96  void Unlock(void);
97 
98 protected:
99  friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
100 
102  vtkMutexLock() = default;
103 
104 private:
105  vtkMutexLock(const vtkMutexLock&) = delete;
106  void operator=(const vtkMutexLock&) = delete;
107 };
108 
109 inline void vtkMutexLock::Lock(void)
110 {
111  this->SimpleMutexLock.Lock();
112 }
113 
114 inline void vtkMutexLock::Unlock(void)
115 {
116  this->SimpleMutexLock.Unlock();
117 }
118 
119 #endif
120 
121 // VTK-HeaderTest-Exclude: vtkMutexLock.h
mutual exclusion locking class
a simple class to control print indentation
Definition: vtkIndent.h:34
mutual exclusion locking class
Definition: vtkMutexLock.h:81
void Lock(void)
Lock the vtkMutexLock.
Definition: vtkMutexLock.h:109
vtkSimpleMutexLock SimpleMutexLock
Definition: vtkMutexLock.h:101
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:114
vtkMutexLock()=default
static vtkMutexLock * New()
abstract base class for most VTK objects
Definition: vtkObject.h:63
void Lock(void)
Lock the vtkMutexLock.
void Unlock(void)
Unlock the vtkMutexLock.
static vtkSimpleMutexLock * New()
virtual ~vtkSimpleMutexLock()
vtkMutexType MutexLock
Definition: vtkMutexLock.h:72
#define VTK_DEPRECATED_IN_9_1_0(reason)
int vtkMutexType
Definition: vtkMutexLock.h:43