ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 /*========================================================================= 00019 * 00020 * Portions of this file are subject to the VTK Toolkit Version 3 copyright. 00021 * 00022 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00023 * 00024 * For complete copyright, license and disclaimer of warranty information 00025 * please refer to the NOTICE file at the top of the ITK source tree. 00026 * 00027 *=========================================================================*/ 00028 #ifndef __itkMutexLock_h 00029 #define __itkMutexLock_h 00030 00031 #include "itkObject.h" 00032 #include "itkObjectFactory.h" 00033 #include "itkThreadSupport.h" 00034 00035 namespace itk 00036 { 00037 00048 class ITKCommon_EXPORT SimpleMutexLock 00049 { 00050 public: 00052 typedef SimpleMutexLock Self; 00053 00055 SimpleMutexLock(); 00056 virtual ~SimpleMutexLock(); 00058 00060 static SimpleMutexLock * New(); 00061 00062 void Delete() { delete this; } 00063 00065 virtual const char * GetNameOfClass() { return "itkSimpleMutexLock"; } 00066 00068 void Lock(void); 00069 00071 void Unlock(void); 00072 00074 MutexType & GetMutexLock() 00075 { 00076 return m_MutexLock; 00077 } 00078 00079 MutexType GetMutexLock() const 00080 { 00081 return *( const_cast< MutexType * >( &m_MutexLock ) ); 00082 } 00083 00084 protected: 00085 MutexType m_MutexLock; 00086 }; 00087 00098 class ITKCommon_EXPORT MutexLock:public Object 00099 { 00100 public: 00102 typedef MutexLock Self; 00103 typedef Object Superclass; 00104 typedef SmartPointer< Self > Pointer; 00105 typedef SmartPointer< const Self > ConstPointer; 00106 00108 itkNewMacro(Self); 00109 00111 itkTypeMacro(MutexLock, Object); 00112 00114 void Lock(void); 00115 00117 void Unlock(void); 00118 00119 protected: 00120 MutexLock() {} 00121 ~MutexLock() {} 00122 00123 SimpleMutexLock m_SimpleMutexLock; 00124 void PrintSelf(std::ostream & os, Indent indent) const; 00125 00126 private: 00127 MutexLock(const Self &); //purposely not implemented 00128 void operator=(const Self &); //purposely not implemented 00129 }; 00130 00131 inline void MutexLock::Lock(void) 00132 { 00133 m_SimpleMutexLock.Lock(); 00134 } 00135 00136 inline void MutexLock::Unlock(void) 00137 { 00138 m_SimpleMutexLock.Unlock(); 00139 } 00140 } //end itk namespace 00141 #endif 00142