VTK  9.2.20230331
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 VTK_ABI_NAMESPACE_BEGIN
45 // Remove with VTK_DEPRECATED_IN_9_2_0 because it was not actually deprecated
46 // in 9.1.0.
47 class VTK_DEPRECATED_IN_9_1_0("Use std::mutex instead") VTKCOMMONCORE_EXPORT vtkCriticalSection
48  : public vtkObject
49 {
50 public:
52 
53  vtkTypeMacro(vtkCriticalSection, vtkObject);
54  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
59  void Lock();
60 
64  void Unlock();
65 
66 protected:
67  std::mutex mtx;
68  vtkCriticalSection() = default;
69  ~vtkCriticalSection() override = default;
70 
71 private:
72  vtkCriticalSection(const vtkCriticalSection&) = delete;
73  void operator=(const vtkCriticalSection&) = delete;
74 };
75 
77 {
78  this->mtx.lock();
79 }
80 
82 {
83  this->mtx.unlock();
84 }
85 
86 VTK_ABI_NAMESPACE_END
87 #endif
88 
89 // VTK-HeaderTest-Exclude: vtkCriticalSection.h
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:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
#define VTK_DEPRECATED_IN_9_1_0(reason)