VTK  9.2.20220703
vtkCriticalSection.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCriticalSection.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 =========================================================================*/
36 #ifndef vtkCriticalSection_h
37 #define vtkCriticalSection_h
38 
39 #include "vtkCommonCoreModule.h" // For export macro
40 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
41 #include "vtkObject.h"
42 #include <mutex> // for std::mutex
43 
44 // Remove with VTK_DEPRECATED_IN_9_2_0 because it was not actually deprecated
45 // in 9.1.0.
46 VTK_DEPRECATED_IN_9_1_0("Use std::mutex instead")
47 class VTKCOMMONCORE_EXPORT vtkCriticalSection : public vtkObject
48 {
49 public:
51 
52  vtkTypeMacro(vtkCriticalSection, vtkObject);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
58  void Lock();
59 
63  void Unlock();
64 
65 protected:
66  std::mutex mtx;
67  vtkCriticalSection() = default;
68  ~vtkCriticalSection() override = default;
69 
70 private:
71  vtkCriticalSection(const vtkCriticalSection&) = delete;
72  void operator=(const vtkCriticalSection&) = delete;
73 };
74 
76 {
77  this->mtx.lock();
78 }
79 
81 {
82  this->mtx.unlock();
83 }
84 
85 #endif
Critical section locking class.
void Unlock()
Unlock the vtkCriticalSection.
static vtkCriticalSection * New()
vtkCriticalSection()=default
void Lock()
Lock the vtkCriticalSection.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
~vtkCriticalSection() override=default
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
#define VTK_DEPRECATED_IN_9_1_0(reason)