Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
VimbaCPP
Source
MutexGuard.cpp
Go to the documentation of this file.
1
/*=============================================================================
2
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
3
4
Redistribution of this file, in original or modified form, without
5
prior written consent of Allied Vision Technologies is prohibited.
6
7
-------------------------------------------------------------------------------
8
9
File: MutexGuard.cpp
10
11
Description: Implementation of a mutex helper class for locking and unlocking.
12
(For internal use only)
13
14
-------------------------------------------------------------------------------
15
16
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
17
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
18
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
=============================================================================*/
28
29
#include <
VimbaCPP/Source/MutexGuard.h
>
30
31
#include <
VimbaCPP/Include/VimbaSystem.h
>
32
33
namespace
AVT
{
34
namespace
VmbAPI {
35
36
MutexGuard::MutexGuard
()
37
{
38
}
39
40
MutexGuard::MutexGuard
( MutexPtr pMutex )
41
{
42
if
(
SP_ISNULL
( pMutex ))
43
{
44
LOG_FREE_TEXT
(
"No mutex passed."
);
45
}
46
else
47
{
48
Protect
( pMutex );
49
}
50
}
51
52
MutexGuard::MutexGuard
( BasicLockablePtr pLockable )
53
{
54
if
(
SP_ISNULL
( pLockable ))
55
{
56
LOG_FREE_TEXT
(
"No mutex passed."
);
57
}
58
else
59
{
60
Protect
( pLockable );
61
}
62
}
63
64
MutexGuard::MutexGuard
(
const
BasicLockable
&rLockable )
65
{
66
Protect
( rLockable );
67
}
68
69
MutexGuard::~MutexGuard
()
70
{
71
Release
();
72
}
73
74
void
MutexGuard::Protect
( MutexPtr pMutex )
75
{
76
if
(
SP_ISNULL
( pMutex ))
77
{
78
LOG_FREE_TEXT
(
"No mutex passed."
);
79
}
80
81
else
if
(
SP_ISEQUAL
( pMutex,
m_pMutex
))
82
{
83
return
;
84
}
85
86
Release
();
87
88
SP_ACCESS
( pMutex )->Lock();
89
m_pMutex
= pMutex;
90
}
91
92
void
MutexGuard::Protect
( BasicLockablePtr pLockable )
93
{
94
if
(
SP_ISNULL
(
SP_ACCESS
( pLockable )->GetMutex() ))
95
{
96
LOG_FREE_TEXT
(
"No mutex passed."
);
97
}
98
else
99
{
100
Protect
(
SP_ACCESS
( pLockable )->GetMutex() );
101
}
102
}
103
104
void
MutexGuard::Protect
(
const
BasicLockable
&rLockable )
105
{
106
Protect
( rLockable.
GetMutex
() );
107
}
108
109
bool
MutexGuard::Release
()
110
{
111
if
(
SP_ISNULL
(
m_pMutex
))
112
{
113
return
false
;
114
}
115
116
SP_ACCESS
(
m_pMutex
)->Unlock();
117
SP_RESET
(
m_pMutex
);
118
119
return
true
;
120
}
121
122
}}
//namespace AVT::VmbAPI
AVT::VmbAPI::BasicLockable
Definition:
BasicLockable.h:39
SP_ISNULL
#define SP_ISNULL(sp)
Definition:
SharedPointerDefines.h:49
SP_RESET
#define SP_RESET(sp)
Definition:
SharedPointerDefines.h:47
SP_ACCESS
#define SP_ACCESS(sp)
Definition:
SharedPointerDefines.h:50
AVT::VmbAPI::MutexGuard::m_pMutex
MutexPtr m_pMutex
Definition:
MutexGuard.h:56
MutexGuard.h
VimbaSystem.h
AVT::VmbAPI::MutexGuard::Protect
void Protect(MutexPtr pMutex)
Definition:
MutexGuard.cpp:74
LOG_FREE_TEXT
#define LOG_FREE_TEXT(txt)
Definition:
LoggerDefines.h:57
AVT::VmbAPI::MutexGuard::Release
bool Release()
Definition:
MutexGuard.cpp:109
AVT::VmbAPI::MutexGuard::MutexGuard
MutexGuard()
Definition:
MutexGuard.cpp:36
SP_ISEQUAL
#define SP_ISEQUAL(sp1, sp2)
Definition:
SharedPointerDefines.h:48
AVT::VmbAPI::BasicLockable::GetMutex
MutexPtr GetMutex() const
Definition:
BasicLockable.cpp:49
AVT::VmbAPI::MutexGuard::~MutexGuard
~MutexGuard()
Definition:
MutexGuard.cpp:69
AVT
Definition:
AncillaryData.h:35
avt_vimba_camera
Author(s): Miquel Massot
, Allied Vision Technologies
autogenerated on Wed Jun 5 2019 22:22:40