Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
igtlMutexLock.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Open IGT Link Library
00004   Module:    $HeadURL: http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink/Source/igtlMutexLock.h $
00005   Language:  C++
00006   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00007   Version:   $Revision: 3460 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010 
00011   This software is distributed WITHOUT ANY WARRANTY; without even
00012   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013   PURPOSE.  See the above copyright notices for more information.
00014 
00015 =========================================================================*/
00016 /*=========================================================================
00017 
00018   Program:   Insight Segmentation & Registration Toolkit
00019   Module:    $RCSfile: itkMutexLock.h,v $
00020   Language:  C++
00021   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00022   Version:   $Revision: 3460 $
00023 
00024   Copyright (c) Insight Software Consortium. All rights reserved.
00025   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00026 
00027   Portions of this code are covered under the VTK copyright.
00028   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00029 
00030      This software is distributed WITHOUT ANY WARRANTY; without even 
00031      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00032      PURPOSE.  See the above copyright notices for more information.
00033 
00034 =========================================================================*/
00035 #ifndef __igtlMutexLock_h
00036 #define __igtlMutexLock_h
00037 
00038 #include "igtlObject.h"
00039 #include "igtlObjectFactory.h"
00040 
00041 #ifdef OpenIGTLink_USE_SPROC
00042 #include <abi_mutex.h>
00043 #endif
00044 
00045 #ifdef OpenIGTLink_USE_PTHREADS
00046 #include <pthread.h>
00047 #endif
00048  
00049 #ifdef OpenIGTLink_USE_WIN32_THREADS
00050 #include "igtlWindows.h"
00051 #endif
00052 
00053 namespace igtl
00054 {
00055 
00056 #ifdef OpenIGTLink_USE_SPROC
00057 typedef abilock_t MutexType;
00058 #endif
00059 
00060 #ifdef OpenIGTLink_USE_PTHREADS
00061 typedef pthread_mutex_t MutexType;
00062 #endif
00063  
00064 #ifdef OpenIGTLink_USE_WIN32_THREADS
00065 typedef HANDLE MutexType;
00066 #endif
00067 
00068 #ifndef OpenIGTLink_USE_SPROC
00069 #ifndef OpenIGTLink_USE_PTHREADS
00070 #ifndef OpenIGTLink_USE_WIN32_THREADS
00071 typedef int MutexType;
00072 #endif
00073 #endif
00074 #endif
00075 
00085 class IGTLCommon_EXPORT SimpleMutexLock
00086 {
00087 public:
00089   typedef SimpleMutexLock       Self;
00090 
00092   SimpleMutexLock();
00093   virtual ~SimpleMutexLock();
00095 
00097   static SimpleMutexLock *New();
00098   //void Delete() {delete this;}
00100 
00102   virtual const char *GetNameOfClass() {return "igtlSimpleMutexLock";};
00103 
00105   void Lock( void );
00106 
00108   void Unlock( void );
00109 
00111   MutexType& GetMutexLock()
00112   {
00113     return m_MutexLock;
00114   }
00115   const MutexType GetMutexLock() const
00116   {
00117     return m_MutexLock;
00118   }
00120 
00121 protected:
00122   MutexType   m_MutexLock;
00123 };
00124 
00134 class IGTLCommon_EXPORT MutexLock : public Object
00135 {
00136 public:
00138   typedef MutexLock       Self;
00139   typedef Object  Superclass;
00140   typedef SmartPointer<Self>  Pointer;
00141   typedef SmartPointer<const Self>  ConstPointer;
00142 
00144   igtlNewMacro(Self);
00145 
00147   igtlTypeMacro(MutexLock,Object);
00148 
00150   void Lock( void );
00151 
00153   void Unlock( void );
00154 
00155 protected:
00156   MutexLock() {}
00157   ~MutexLock() {}
00158   
00159   SimpleMutexLock   m_SimpleMutexLock;
00160   void PrintSelf(std::ostream& os) const;
00161   
00162 private:
00163   MutexLock(const Self&); //purposely not implemented
00164   void operator=(const Self&); //purposely not implemented
00165 };
00166 
00167 
00168 inline void MutexLock::Lock( void )
00169 {
00170   m_SimpleMutexLock.Lock();
00171 }
00172 
00173 inline void MutexLock::Unlock( void )
00174 {
00175   m_SimpleMutexLock.Unlock();
00176 }
00177 
00178 
00179 }//end igtl namespace
00180 #endif
00181 

Generated at Wed Apr 27 2011 00:08:07 for OpenIGTLink by doxygen 1.7.4 written by Dimitri van Heesch, © 1997-2000