Mutex.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: Mutex.cpp
10 
11  Description: Implementation of class AVT::VmbAPI::Mutex.
12 
13 -------------------------------------------------------------------------------
14 
15  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
17  NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
23  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 =============================================================================*/
27 
28 #include <math.h>
29 
30 #include <VimbaCPP/Include/Mutex.h>
32 
33 namespace AVT {
34 namespace VmbAPI {
35 
36 Mutex::Mutex( bool bInitLock )
37 #ifdef WIN32
38  : m_hMutex( NULL )
39 #endif
40 {
41 #ifdef WIN32
42  m_hMutex = CreateMutex( NULL, FALSE, NULL );
43  if( NULL == m_hMutex )
44  {
45  LOG_FREE_TEXT( "Could not create mutex." );
46  throw std::bad_alloc();
47  }
48 #else
49  pthread_mutex_init(&m_Mutex, NULL);
50 #endif
51 
52  if( true == bInitLock )
53  {
54  Lock();
55  }
56 }
57 
59 {
60 #ifdef WIN32
61  CloseHandle( m_hMutex );
62 #else
63  pthread_mutex_destroy(&m_Mutex);
64 #endif
65 }
66 
68 {
69  // No copy ctor
70 }
71 
73 {
74  // No assignment operator
75  return *this;
76 }
77 
79 {
80 #ifdef WIN32
81  WaitForSingleObject( m_hMutex, INFINITE );
82 #else
83  pthread_mutex_lock( &m_Mutex );
84 #endif
85 }
86 
88 {
89 #ifdef WIN32
90  ReleaseMutex( m_hMutex );
91 #else
92  pthread_mutex_unlock( &m_Mutex );
93 #endif
94 }
95 
96 }} //namespace AVT::VmbAPI
Mutex & operator=(const Mutex &)
Definition: Mutex.cpp:72
IMEXPORT void Unlock()
Definition: Mutex.cpp:87
IMEXPORT void Lock()
Definition: Mutex.cpp:78
IMEXPORT Mutex(bool bInitLock=false)
Definition: Mutex.cpp:36
#define LOG_FREE_TEXT(txt)
Definition: LoggerDefines.h:56
IMEXPORT ~Mutex()
Definition: Mutex.cpp:58
pthread_mutex_t m_Mutex
Definition: Mutex.h:55


avt_vimba_camera
Author(s): Allied Vision Technologies, Miquel Massot
autogenerated on Fri Jun 2 2023 02:21:10