VTK  9.3.20231130
vtkCriticalSection.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
24 #ifndef vtkCriticalSection_h
25 #define vtkCriticalSection_h
26 
27 #include "vtkCommonCoreModule.h" // For export macro
28 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
29 #include "vtkObject.h"
30 #include <mutex> // for std::mutex
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 // Remove with VTK_DEPRECATED_IN_9_2_0 because it was not actually deprecated
34 // in 9.1.0.
35 class VTK_DEPRECATED_IN_9_1_0("Use std::mutex instead") VTKCOMMONCORE_EXPORT vtkCriticalSection
36  : public vtkObject
37 {
38 public:
40 
41  vtkTypeMacro(vtkCriticalSection, vtkObject);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
47  void Lock();
48 
52  void Unlock();
53 
54 protected:
55  std::mutex mtx;
56  vtkCriticalSection() = default;
57  ~vtkCriticalSection() override = default;
58 
59 private:
60  vtkCriticalSection(const vtkCriticalSection&) = delete;
61  void operator=(const vtkCriticalSection&) = delete;
62 };
63 
65 {
66  this->mtx.lock();
67 }
68 
70 {
71  this->mtx.unlock();
72 }
73 
74 VTK_ABI_NAMESPACE_END
75 #endif
76 
77 // 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:108
abstract base class for most VTK objects
Definition: vtkObject.h:161
#define VTK_DEPRECATED_IN_9_1_0(reason)