OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkCriticalSection.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkCriticalSection.h,v $
5   Language:  C++
6   Date:      $Date: 2003/01/29 21:14:52 $
7   Version:   $Revision: 1.15 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18 // .NAME vtkCriticalSection - critical section locking class
19 // .SECTION Description
20 // vtkCriticalSection allows the locking of variables which are accessed 
21 // through different threads.  This header file also defines 
22 // vtkSimpleCriticalSection which is not a subclass of vtkObject.
23 // The API is identical to that of vtkMutexLock, and the behavior is
24 // identical as well, except on Windows 9x/NT platforms. The only difference
25 // on these platforms is that vtkMutexLock is more flexible, in that
26 // it works across processes as well as across threads, but also costs
27 // more, in that it evokes a 600-cycle x86 ring transition. The 
28 // vtkCriticalSection provides a higher-performance equivalent (on 
29 // Windows) but won't work across processes. Since it is unclear how,
30 // in vtk, an object at the vtk level can be shared across processes
31 // in the first place, one should use vtkCriticalSection unless one has
32 // a very good reason to use vtkMutexLock. If higher-performance equivalents
33 // for non-Windows platforms (Irix, SunOS, etc) are discovered, they
34 // should replace the implementations in this class
35
36 #ifndef __vtkCriticalSection_h
37 #define __vtkCriticalSection_h
38
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 <winbase.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 VTK_COMMON_EXPORT vtkSimpleCriticalSection
68 {
69 public:
70   vtkSimpleCriticalSection()
71     {
72       this->Init();
73     }
74
75   vtkSimpleCriticalSection(int isLocked)
76     {
77       this->Init();
78       if(isLocked)
79         {
80         this->Lock();
81         }
82     }
83
84   void Init();
85
86   virtual ~vtkSimpleCriticalSection();
87
88   static vtkSimpleCriticalSection *New();
89
90   // What's the point of these (here and in MutexLock)? This class
91   // is not part of the hierarchy!! -CRV
92   virtual const char *GetClassName() {return "vtkSimpleCriticalSection";};
93   virtual int IsA(const char *name);
94   static vtkSimpleCriticalSection *SafeDownCast(vtkSimpleCriticalSection *o);
95
96   void Delete() {delete this;}
97   
98   // Description:
99   // Lock the vtkCriticalSection
100   void Lock( void );
101
102   // Description:
103   // Unlock the vtkCriticalSection
104   void Unlock( void );
105
106 protected:
107   vtkCritSecType   CritSec;
108 };
109
110 //ETX
111
112 class VTK_COMMON_EXPORT vtkCriticalSection : public vtkObject
113 {
114 public:
115   static vtkCriticalSection *New();
116
117   vtkTypeRevisionMacro(vtkCriticalSection,vtkObject);
118   void PrintSelf(ostream& os, vtkIndent indent);
119   
120   // Description:
121   // Lock the vtkCriticalSection
122   void Lock( void );
123
124   // Description:
125   // Unlock the vtkCriticalSection
126   void Unlock( void );
127
128 protected:
129   vtkSimpleCriticalSection   SimpleCriticalSection;
130   vtkCriticalSection() {};
131 private:
132   vtkCriticalSection(const vtkCriticalSection&);  // Not implemented.
133   void operator=(const vtkCriticalSection&);  // Not implemented.
134 };
135
136
137 inline void vtkCriticalSection::Lock( void )
138 {
139   this->SimpleCriticalSection.Lock();
140 }
141
142 inline void vtkCriticalSection::Unlock( void )
143 {
144   this->SimpleCriticalSection.Unlock();
145 }
146
147 #endif