VTK  9.1.20211024
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 "vtkObject.h"
41 #include <mutex> // for std::mutex
42 
43 class VTKCOMMONCORE_EXPORT vtkCriticalSection : public vtkObject
44 {
45 public:
47 
48  vtkTypeMacro(vtkCriticalSection, vtkObject);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
54  void Lock();
55 
59  void Unlock();
60 
61 protected:
62  std::mutex mtx;
63  vtkCriticalSection() = default;
64  ~vtkCriticalSection() override = default;
65 
66 private:
67  vtkCriticalSection(const vtkCriticalSection&) = delete;
68  void operator=(const vtkCriticalSection&) = delete;
69 };
70 
72 {
73  this->mtx.lock();
74 }
75 
77 {
78  this->mtx.unlock();
79 }
80 
81 #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:113
abstract base class for most VTK objects
Definition: vtkObject.h:82