OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkMutexLock.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkMutexLock.h,v $
5   Language:  C++
6   Date:      $Date: 2003/01/29 21:14:52 $
7   Version:   $Revision: 1.25 $
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 vtkMutexLock - mutual exclusion locking class
19 // .SECTION Description
20 // vtkMutexLock allows the locking of variables which are accessed 
21 // through different threads.  This header file also defines 
22 // vtkSimpleMutexLock which is not a subclass of vtkObject.
23
24 #ifndef __vtkMutexVariable_h
25 #define __vtkMutexVariable_h
26
27
28 #include "vtkObject.h"
29
30 //BTX
31
32 #ifdef VTK_USE_SPROC
33 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
34 typedef abilock_t vtkMutexType;
35 #endif
36
37 #if defined(VTK_USE_PTHREADS) || defined(VTK_HP_PTHREADS)
38 #include <pthread.h> // Needed for PTHREAD implementation of mutex
39 typedef pthread_mutex_t vtkMutexType;
40 #endif
41  
42 #ifdef VTK_USE_WIN32_THREADS
43 #include <winbase.h> // Needed for WIN32 implementation of mutex
44 typedef HANDLE vtkMutexType;
45 #endif
46
47 #ifndef VTK_USE_SPROC
48 #ifndef VTK_USE_PTHREADS
49 #ifndef VTK_USE_WIN32_THREADS
50 typedef int vtkMutexType;
51 #endif
52 #endif
53 #endif
54
55 // Mutex lock that is not a vtkObject.
56 class VTK_COMMON_EXPORT vtkSimpleMutexLock
57 {
58 public:
59   // left public purposely
60   vtkSimpleMutexLock();
61   virtual ~vtkSimpleMutexLock();
62
63   static vtkSimpleMutexLock *New();
64
65   virtual const char *GetClassName() {return "vtkSimpleMutexLock";};
66   virtual int IsA(const char *name);
67   static vtkSimpleMutexLock *SafeDownCast(vtkSimpleMutexLock *o);
68
69   void Delete() {delete this;}
70   
71   // Description:
72   // Lock the vtkMutexLock
73   void Lock( void );
74
75   // Description:
76   // Unlock the vtkMutexLock
77   void Unlock( void );
78
79 protected:
80   vtkMutexType   MutexLock;
81 };
82
83 //ETX
84
85 class VTK_COMMON_EXPORT vtkMutexLock : public vtkObject
86 {
87 public:
88   static vtkMutexLock *New();
89
90   vtkTypeRevisionMacro(vtkMutexLock,vtkObject);
91   void PrintSelf(ostream& os, vtkIndent indent);
92   
93   // Description:
94   // Lock the vtkMutexLock
95   void Lock( void );
96
97   // Description:
98   // Unlock the vtkMutexLock
99   void Unlock( void );
100
101 protected:
102   vtkSimpleMutexLock   SimpleMutexLock;
103   vtkMutexLock() {};
104 private:
105   vtkMutexLock(const vtkMutexLock&);  // Not implemented.
106   void operator=(const vtkMutexLock&);  // Not implemented.
107 };
108
109
110 inline void vtkMutexLock::Lock( void )
111 {
112   this->SimpleMutexLock.Lock();
113 }
114
115 inline void vtkMutexLock::Unlock( void )
116 {
117   this->SimpleMutexLock.Unlock();
118 }
119
120 #endif