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  (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 
29 #include <math.h>
30 
31 #include <VimbaCPP/Include/Mutex.h>
33 
34 namespace AVT {
35 namespace VmbAPI {
36 
37 Mutex::Mutex( bool bInitLock )
38 #ifdef WIN32
39  : m_hMutex( NULL )
40 #endif
41 {
42 #ifdef WIN32
43  m_hMutex = CreateMutex( NULL, FALSE, NULL );
44  if( NULL == m_hMutex )
45  {
46  LOG_FREE_TEXT( "Could not create mutex." );
47  throw std::bad_alloc();
48  }
49 #else
50  pthread_mutex_init(&m_Mutex, NULL);
51 #endif
52 
53  if( true == bInitLock )
54  {
55  Lock();
56  }
57 }
58 
60 {
61 #ifdef WIN32
62  CloseHandle( m_hMutex );
63 #else
64  pthread_mutex_destroy(&m_Mutex);
65 #endif
66 }
67 
69 {
70  // No copy ctor
71 }
72 
74 {
75  // No assignment operator
76  return *this;
77 }
78 
80 {
81 #ifdef WIN32
82  WaitForSingleObject( m_hMutex, INFINITE );
83 #else
84  pthread_mutex_lock( &m_Mutex );
85 #endif
86 }
87 
89 {
90 #ifdef WIN32
91  ReleaseMutex( m_hMutex );
92 #else
93  pthread_mutex_unlock( &m_Mutex );
94 #endif
95 }
96 
97 }} //namespace AVT::VmbAPI
Mutex & operator=(const Mutex &)
Definition: Mutex.cpp:73
IMEXPORT void Unlock()
Definition: Mutex.cpp:88
IMEXPORT void Lock()
Definition: Mutex.cpp:79
IMEXPORT Mutex(bool bInitLock=false)
Definition: Mutex.cpp:37
#define LOG_FREE_TEXT(txt)
Definition: LoggerDefines.h:57
IMEXPORT ~Mutex()
Definition: Mutex.cpp:59
pthread_mutex_t m_Mutex
Definition: Mutex.h:56


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Wed Jun 5 2019 22:22:40