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 =========================================================================*/
27 #ifndef vtkMutexLock_h
28 #define vtkMutexLock_h
29 
30 
31 #include "vtkCommonCoreModule.h" // For export macro
32 #include "vtkObject.h"
33 
34 #if defined(VTK_USE_PTHREADS)
35 #include <pthread.h> // Needed for PTHREAD implementation of mutex
36 typedef pthread_mutex_t vtkMutexType;
37 #endif
38 
39 #ifdef VTK_USE_WIN32_THREADS
40 typedef vtkWindowsHANDLE vtkMutexType;
41 #endif
42 
43 #ifndef VTK_USE_PTHREADS
44 #ifndef VTK_USE_WIN32_THREADS
45 typedef int vtkMutexType;
46 #endif
47 #endif
48 
49 // Mutex lock that is not a vtkObject.
50 class VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
51 {
52 public:
53  // left public purposely
55  virtual ~vtkSimpleMutexLock();
56 
57  static vtkSimpleMutexLock *New();
58 
59  void Delete() {delete this;}
60 
64  void Lock( void );
65 
69  void Unlock( void );
70 
71 protected:
74 
75 private:
76  vtkSimpleMutexLock(const vtkSimpleMutexLock& other) = delete;
77  vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs) = delete;
78 };
79 
80 class VTKCOMMONCORE_EXPORT vtkMutexLock : 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 
100  friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
101 
104 private:
105  vtkMutexLock(const vtkMutexLock&) = delete;
106  void operator=(const vtkMutexLock&) = delete;
107 };
108 
109 
110 inline void vtkMutexLock::Lock( void )
111 {
112  this->SimpleMutexLock.Lock();
113 }
114 
115 inline void vtkMutexLock::Unlock( void )
116 {
117  this->SimpleMutexLock.Unlock();
118 }
119 
120 #endif
mutual exclusion locking class
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:115
void Lock(void)
Lock the vtkMutexLock.
Definition: vtkMutexLock.h:110
vtkMutexType MutexLock
Definition: vtkMutexLock.h:73
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSimpleMutexLock SimpleMutexLock
Definition: vtkMutexLock.h:102
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:80
int vtkMutexType
Definition: vtkMutexLock.h:45