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