VTK
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 "vtkObject.h"
39 
40 //BTX
41 
42 #ifdef VTK_USE_SPROC
43 #include <abi_mutex.h> // Needed for sproc implementation of mutex
44 typedef abilock_t vtkCritSecType;
45 #endif
46 
47 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
48 #include <pthread.h> // Needed for pthreads implementation of mutex
49 typedef pthread_mutex_t vtkCritSecType;
50 #endif
51 
52 #ifdef VTK_USE_WIN32_THREADS
53 # include "vtkWindows.h" // Needed for win32 implementation of mutex
54 typedef CRITICAL_SECTION vtkCritSecType;
55 #endif
56 
57 #ifndef VTK_USE_SPROC
58 #ifndef VTK_USE_PTHREADS
59 #ifndef VTK_USE_WIN32_THREADS
60 typedef int vtkCritSecType;
61 #endif
62 #endif
63 #endif
64 
65 // Critical Section object that is not a vtkObject.
67 {
68 public:
69  // Default cstor
71  {
72  this->Init();
73  }
74  // Construct object locked if isLocked is different from 0
76  {
77  this->Init();
78  if(isLocked)
79  {
80  this->Lock();
81  }
82  }
83  // Destructor
84  virtual ~vtkSimpleCriticalSection();
85 
86  // Default vtkObject API
87  static vtkSimpleCriticalSection *New();
88  void Delete()
89  {
90  delete this;
91  }
92 
93  void Init();
94 
96  void Lock();
97 
99  void Unlock();
100 
101 protected:
103 };
104 
105 //ETX
106 
108 {
109 public:
110  static vtkCriticalSection *New();
111 
113  void PrintSelf(ostream& os, vtkIndent indent);
114 
116  void Lock();
117 
119  void Unlock();
120 
121 protected:
125 
126 private:
127  vtkCriticalSection(const vtkCriticalSection&); // Not implemented.
128  void operator=(const vtkCriticalSection&); // Not implemented.
129 };
130 
131 
133 {
134  this->SimpleCriticalSection.Lock();
135 }
136 
138 {
140 }
141 
142 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkSimpleCriticalSection SimpleCriticalSection
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
int vtkCritSecType
vtkSimpleCriticalSection(int isLocked)
#define VTK_COMMON_EXPORT
Critical section locking class.
static vtkObject * New()