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 #ifdef VTK_USE_SPROC
35 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
36 typedef abilock_t vtkMutexType;
37 #endif
38 
39 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
40 #include <pthread.h> // Needed for PTHREAD implementation of mutex
41 typedef pthread_mutex_t vtkMutexType;
42 #endif
43 
44 #ifdef VTK_USE_WIN32_THREADS
45 typedef vtkWindowsHANDLE vtkMutexType;
46 #endif
47 
48 #ifndef VTK_USE_SPROC
49 #ifndef VTK_USE_PTHREADS
50 #ifndef VTK_USE_WIN32_THREADS
51 typedef int vtkMutexType;
52 #endif
53 #endif
54 #endif
55 
56 // Mutex lock that is not a vtkObject.
57 class VTKCOMMONCORE_EXPORT vtkSimpleMutexLock
58 {
59 public:
60  // left public purposely
62  virtual ~vtkSimpleMutexLock();
63 
64  static vtkSimpleMutexLock *New();
65 
66  void Delete() {delete this;}
67 
71  void Lock( void );
72 
76  void Unlock( void );
77 
78 protected:
81 
82 private:
83  vtkSimpleMutexLock(const vtkSimpleMutexLock& other) VTK_DELETE_FUNCTION;
84  vtkSimpleMutexLock& operator=(const vtkSimpleMutexLock& rhs) VTK_DELETE_FUNCTION;
85 };
86 
87 class VTKCOMMONCORE_EXPORT vtkMutexLock : public vtkObject
88 {
89 public:
90  static vtkMutexLock *New();
91 
92  vtkTypeMacro(vtkMutexLock,vtkObject);
93  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
94 
98  void Lock( void );
99 
103  void Unlock( void );
104 
105 protected:
106 
107  friend class vtkConditionVariable; // needs to get at SimpleMutexLock.
108 
111 private:
112  vtkMutexLock(const vtkMutexLock&) VTK_DELETE_FUNCTION;
113  void operator=(const vtkMutexLock&) VTK_DELETE_FUNCTION;
114 };
115 
116 
117 inline void vtkMutexLock::Lock( void )
118 {
119  this->SimpleMutexLock.Lock();
120 }
121 
122 inline void vtkMutexLock::Unlock( void )
123 {
124  this->SimpleMutexLock.Unlock();
125 }
126 
127 #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:122
void Lock(void)
Lock the vtkMutexLock.
vtkMutexType MutexLock
Definition: vtkMutexLock.h:80
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSimpleMutexLock SimpleMutexLock
Definition: vtkMutexLock.h:109
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:87
int vtkMutexType
Definition: vtkMutexLock.h:51