ConditionHelper.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: ConditionHelper.cpp
10 
11  Description: Implementation of helper class for conditions.
12  (This include file is 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 
30 
32 
33 namespace AVT {
34 namespace VmbAPI {
35 
37  : m_nNumListReads( 0 )
38  , m_bIsWritingList( false )
39  , m_bExclusive( false )
40 {
41 }
42 
44 {
45  return EnterReadLock( rLockable.GetMutex() );
46 }
47 bool ConditionHelper::EnterReadLock( MutexPtr pMutex )
48 {
49  MutexGuard guard( pMutex );
50  if ( true == m_bExclusive )
51  {
52  guard.Release();
53  return false;
54  }
55  while ( true == m_bIsWritingList )
56  {
57  m_WriteCondition.Wait( pMutex );
58  }
60  guard.Release();
61 
62  return true;
63 }
64 
66 {
67  ExitReadLock( rLockable.GetMutex() );
68 }
69 void ConditionHelper::ExitReadLock( MutexPtr pMutex )
70 {
71  MutexGuard guard( pMutex );
72  if ( 0 == --m_nNumListReads )
73  {
75  }
76  guard.Release();
77 }
78 
79 bool ConditionHelper::EnterWriteLock( BasicLockable &rLockable, bool bExclusive )
80 {
81  return EnterWriteLock( rLockable.GetMutex(), bExclusive );
82 }
83 bool ConditionHelper::EnterWriteLock( MutexPtr pMutex, bool bExclusive )
84 {
85  MutexGuard guard( pMutex );
86  if ( true == m_bExclusive )
87  {
88  guard.Release();
89  return false;
90  }
91  while ( true == m_bIsWritingList )
92  {
93  m_WriteCondition.Wait( pMutex );
94  }
95  m_bIsWritingList = true;
96  m_bExclusive = bExclusive;
97  while ( 0 < m_nNumListReads )
98  {
99  m_ReadCondition.Wait( pMutex );
100  }
101  guard.Release();
102 
103  return true;
104 }
105 
107 {
108  ExitWriteLock( rLockable.GetMutex() );
109 }
110 void ConditionHelper::ExitWriteLock( MutexPtr pMutex )
111 {
112  MutexGuard guard( pMutex );
113  m_bIsWritingList = false;
114  m_bExclusive = false;
116  guard.Release();
117 }
118 
119 }} // namespace AV::VimbaAPI
bool EnterWriteLock(BasicLockable &rLockable, bool bExclusive=false)
void Signal(bool bSingle=false)
Definition: Condition.cpp:84
void ExitWriteLock(BasicLockable &rLockable)
MutexPtr GetMutex() const
void ExitReadLock(BasicLockable &rLockable)
void Wait(const BasicLockable &rLockable)
Definition: Condition.cpp:42
bool EnterReadLock(BasicLockable &rLockable)


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Mon Jun 10 2019 12:50:38