VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 =========================================================================*/
35 #ifndef __vtkCriticalSection_h
36 #define __vtkCriticalSection_h
37 
38 #include "vtkCommonCoreModule.h" // For export macro
39 #include "vtkObject.h"
40 
41 //BTX
42 
43 #ifdef VTK_USE_SPROC
44 #include <abi_mutex.h> // Needed for sproc implementation of mutex
45 typedef abilock_t vtkCritSecType;
46 #endif
47 
48 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
49 #include <pthread.h> // Needed for pthreads implementation of mutex
50 typedef pthread_mutex_t vtkCritSecType;
51 #endif
52 
53 #ifdef VTK_USE_WIN32_THREADS
54 # include "vtkWindows.h" // Needed for win32 implementation of mutex
55 typedef CRITICAL_SECTION vtkCritSecType;
56 #endif
57 
58 #ifndef VTK_USE_SPROC
59 #ifndef VTK_USE_PTHREADS
60 #ifndef VTK_USE_WIN32_THREADS
61 typedef int vtkCritSecType;
62 #endif
63 #endif
64 #endif
65 
66 // Critical Section object that is not a vtkObject.
67 class VTKCOMMONCORE_EXPORT vtkSimpleCriticalSection
68 {
69 public:
70  // Default cstor
72  {
73  this->Init();
74  }
75  // Construct object locked if isLocked is different from 0
77  {
78  this->Init();
79  if(isLocked)
80  {
81  this->Lock();
82  }
83  }
84  // Destructor
85  virtual ~vtkSimpleCriticalSection();
86 
87  // Default vtkObject API
88  static vtkSimpleCriticalSection *New();
89  void Delete()
90  {
91  delete this;
92  }
93 
94  void Init();
95 
97  void Lock();
98 
100  void Unlock();
101 
102 protected:
104 };
105 
106 //ETX
107 
108 class VTKCOMMONCORE_EXPORT vtkCriticalSection : public vtkObject
109 {
110 public:
111  static vtkCriticalSection *New();
112 
114  void PrintSelf(ostream& os, vtkIndent indent);
115 
117  void Lock();
118 
120  void Unlock();
121 
122 protected:
126 
127 private:
128  vtkCriticalSection(const vtkCriticalSection&); // Not implemented.
129  void operator=(const vtkCriticalSection&); // Not implemented.
130 };
131 
132 
134 {
135  this->SimpleCriticalSection.Lock();
136 }
137 
139 {
141 }
142 
143 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkSimpleCriticalSection SimpleCriticalSection
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
int vtkCritSecType
vtkSimpleCriticalSection(int isLocked)
Critical section locking class.
static vtkObject * New()