Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMutexLock.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMutexLock.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:17 $
00007   Version:   $Revision: 1.21 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012   Portions of this code are covered under the VTK copyright.
00013   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00014 
00015      This software is distributed WITHOUT ANY WARRANTY; without even 
00016      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00017      PURPOSE.  See the above copyright notices for more information.
00018 
00019 =========================================================================*/
00020 #ifndef __itkMutexLock_h
00021 #define __itkMutexLock_h
00022 
00023 #include "itkObject.h"
00024 #include "itkObjectFactory.h"
00025 
00026 #ifdef ITK_USE_SPROC
00027 #include <abi_mutex.h>
00028 #endif
00029 
00030 #ifdef ITK_USE_PTHREADS
00031 #include <pthread.h>
00032 #endif
00033  
00034 #ifdef ITK_USE_WIN32_THREADS
00035 #include "itkWindows.h"
00036 #endif
00037 
00038 namespace itk
00039 {
00040 
00041 #ifdef ITK_USE_SPROC
00042 typedef abilock_t MutexType;
00043 #endif
00044 
00045 #ifdef ITK_USE_PTHREADS
00046 typedef pthread_mutex_t MutexType;
00047 #endif
00048  
00049 #ifdef ITK_USE_WIN32_THREADS
00050 typedef HANDLE MutexType;
00051 #endif
00052 
00053 #ifndef ITK_USE_SPROC
00054 #ifndef ITK_USE_PTHREADS
00055 #ifndef ITK_USE_WIN32_THREADS
00056 typedef int MutexType;
00057 #endif
00058 #endif
00059 #endif
00060 
00070 class ITKCommon_EXPORT SimpleMutexLock
00071 {
00072 public:
00074   typedef SimpleMutexLock       Self;
00075 
00077   SimpleMutexLock();
00078   virtual ~SimpleMutexLock();
00080 
00082   static SimpleMutexLock *New();
00083   void Delete() {delete this;}
00085 
00087   virtual const char *GetNameOfClass() {return "itkSimpleMutexLock";};
00088 
00090   void Lock( void );
00091 
00093   void Unlock( void );
00094 
00096   MutexType& GetMutexLock()
00097   {
00098     return m_MutexLock;
00099   }
00100   const MutexType GetMutexLock() const
00101   {
00102     return m_MutexLock;
00103   }
00105 
00106 protected:
00107   MutexType   m_MutexLock;
00108 };
00109 
00119 class ITKCommon_EXPORT MutexLock : public Object
00120 {
00121 public:
00123   typedef MutexLock       Self;
00124   typedef Object  Superclass;
00125   typedef SmartPointer<Self>  Pointer;
00126   typedef SmartPointer<const Self>  ConstPointer;
00127 
00129   itkNewMacro(Self);
00130 
00132   itkTypeMacro(MutexLock,Object);
00133 
00135   void Lock( void );
00136 
00138   void Unlock( void );
00139 
00140 protected:
00141   MutexLock() {}
00142   ~MutexLock() {}
00143   
00144   SimpleMutexLock   m_SimpleMutexLock;
00145   void PrintSelf(std::ostream& os, Indent indent) const;
00146   
00147 private:
00148   MutexLock(const Self&); //purposely not implemented
00149   void operator=(const Self&); //purposely not implemented
00150 };
00151 
00152 
00153 inline void MutexLock::Lock( void )
00154 {
00155   m_SimpleMutexLock.Lock();
00156 }
00157 
00158 inline void MutexLock::Unlock( void )
00159 {
00160   m_SimpleMutexLock.Unlock();
00161 }
00162 
00163 
00164 }//end itk namespace
00165 #endif
00166 

Generated at Tue Jul 29 21:22:33 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000