KWStyle - itkMutexLock.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkMutexLock.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:42 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 DEF =========================================================================*/
20 #include "itkMutexLock.h"
21
22 namespace itk
23 {
24
25
26 // New for the SimpleMutex
27 SimpleMutexLock *SimpleMutexLock::New()
28 {
29   return new SimpleMutexLock;
30 }
31
32 // Construct a new MutexLock 
33 SimpleMutexLock::SimpleMutexLock()
34 {
35 #ifdef ITK_USE_SPROC
36   init_lock( &m_MutexLock );
37 #endif
38
39 #ifdef ITK_USE_WIN32_THREADS
40   m_MutexLock = CreateMutex( NULL, FALSE, NULL ); 
41 #endif
42
43 #ifdef ITK_USE_PTHREADS
44 #ifdef ITK_HP_PTHREADS
45   pthread_mutex_init(&m_MutexLock, pthread_mutexattr_default);
46 IND #else
47   pthread_mutex_init(&m_MutexLock, NULL);
48 #endif
49 #endif
50
51 }
52
53 // Destruct the MutexVariable
54 SimpleMutexLock::~SimpleMutexLock()
55 {
56 #ifdef ITK_USE_WIN32_THREADS
57   CloseHandle(m_MutexLock);
58 #endif
59
60 #ifdef ITK_USE_PTHREADS
61   pthread_mutex_destroy( &m_MutexLock);
62 #endif
63 }
64
65 // Lock the MutexLock
66 void SimpleMutexLock::Lock()
67 {
68 #ifdef ITK_USE_SPROC
69   spin_lock( &m_MutexLock );
70 #endif
71
72 #ifdef ITK_USE_WIN32_THREADS
73   WaitForSingleObject( m_MutexLock, INFINITE );
74 #endif
75
76 #ifdef ITK_USE_PTHREADS
77   pthread_mutex_lock( &m_MutexLock);
78 #endif
79 }
80
81 // Unlock the MutexLock
82 void SimpleMutexLock::Unlock()
83 {
84 #ifdef ITK_USE_SPROC
85   release_lock( &m_MutexLock );
86 #endif
87
88 #ifdef ITK_USE_WIN32_THREADS
89   ReleaseMutex( m_MutexLock );
90 #endif
91
92 #ifdef ITK_USE_PTHREADS
93   pthread_mutex_unlock( &m_MutexLock);
94 #endif
95 }
96
97 void MutexLock::PrintSelf(std::ostream& os, Indent indent) const
98 {
99   Superclass::PrintSelf(os, indent);
100 }
101
102 }//end namespace itk
103

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:26PM
© Kitware Inc.