1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkMutexLock.h,v $
6 Date: $Date: 2003/01/29 21:14:52 $
7 Version: $Revision: 1.25 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
24 #ifndef __vtkMutexVariable_h
25 #define __vtkMutexVariable_h
28 #include "vtkObject.h"
33 #include <abi_mutex.h> // Needed for SPROC implementation of mutex
34 typedef abilock_t vtkMutexType;
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;
42 #ifdef VTK_USE_WIN32_THREADS
43 #include <winbase.h> // Needed for WIN32 implementation of mutex
44 typedef HANDLE vtkMutexType;
48 #ifndef VTK_USE_PTHREADS
49 #ifndef VTK_USE_WIN32_THREADS
50 typedef int vtkMutexType;
55 // Mutex lock that is not a vtkObject.
56 class VTK_COMMON_EXPORT vtkSimpleMutexLock
59 // left public purposely
61 virtual ~vtkSimpleMutexLock();
63 static vtkSimpleMutexLock *New();
65 virtual const char *GetClassName() {return "vtkSimpleMutexLock";};
66 virtual int IsA(const char *name);
67 static vtkSimpleMutexLock *SafeDownCast(vtkSimpleMutexLock *o);
69 void Delete() {delete this;}
72 // Lock the vtkMutexLock
76 // Unlock the vtkMutexLock
80 vtkMutexType MutexLock;
85 class VTK_COMMON_EXPORT vtkMutexLock : public vtkObject
88 static vtkMutexLock *New();
90 vtkTypeRevisionMacro(vtkMutexLock,vtkObject);
91 void PrintSelf(ostream& os, vtkIndent indent);
94 // Lock the vtkMutexLock
98 // Unlock the vtkMutexLock
102 vtkSimpleMutexLock SimpleMutexLock;
105 vtkMutexLock(const vtkMutexLock&); // Not implemented.
106 void operator=(const vtkMutexLock&); // Not implemented.
110 inline void vtkMutexLock::Lock( void )
112 this->SimpleMutexLock.Lock();
115 inline void vtkMutexLock::Unlock( void )
117 this->SimpleMutexLock.Unlock();