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