Mutex.cpp
Go to the documentation of this file.
00001 /*=============================================================================
00002   Copyright (C) 2012 Allied Vision Technologies.  All Rights Reserved.
00003 
00004   Redistribution of this file, in original or modified form, without
00005   prior written consent of Allied Vision Technologies is prohibited.
00006 
00007 -------------------------------------------------------------------------------
00008 
00009   File:        Mutex.cpp
00010 
00011   Description: Implementation of class AVT::VmbAPI::Mutex.
00012                (This include file is for internal use only.)
00013 
00014 -------------------------------------------------------------------------------
00015 
00016   THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00017   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
00018   NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR  PURPOSE ARE
00019   DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
00020   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00021   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  
00023   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
00024   TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00025   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 =============================================================================*/
00028 
00029 #include <math.h>
00030 
00031 #include <VimbaCPP/Include/Mutex.h>
00032 #include <VimbaCPP/Include/LoggerDefines.h>
00033 
00034 namespace AVT {
00035 namespace VmbAPI {
00036 
00037 Mutex::Mutex( bool bInitLock )
00038 #ifdef WIN32
00039     :   m_hMutex( NULL )
00040 #endif
00041 {
00042 #ifdef WIN32
00043     m_hMutex = CreateMutex( NULL, FALSE, NULL );
00044     if( NULL == m_hMutex )
00045     {
00046         LOG_FREE_TEXT( "Could not create mutex." );
00047         throw std::bad_alloc();
00048     }
00049 #else
00050     pthread_mutex_init(&m_Mutex, NULL);
00051 #endif
00052 
00053     if( true == bInitLock )
00054     {
00055         Lock();
00056     }
00057 }
00058 
00059 Mutex::~Mutex()
00060 {  
00061 #ifdef WIN32
00062     CloseHandle( m_hMutex );
00063 #else
00064     pthread_mutex_destroy(&m_Mutex);
00065 #endif
00066 }
00067 
00068 Mutex::Mutex( const Mutex& )
00069 {
00070     // No copy ctor
00071 }
00072 
00073 Mutex& Mutex::operator=( const Mutex& )
00074 {
00075     // No assignment operator
00076     return *this;
00077 }
00078 
00079 void Mutex::Lock()
00080 {
00081 #ifdef WIN32
00082     WaitForSingleObject( m_hMutex, INFINITE );
00083 #else
00084     pthread_mutex_lock( &m_Mutex );
00085 #endif
00086 }
00087 
00088 void Mutex::Unlock()
00089 {  
00090 #ifdef WIN32
00091     ReleaseMutex( m_hMutex );
00092 #else
00093     pthread_mutex_unlock( &m_Mutex );
00094 #endif
00095 }
00096 
00097 }} //namespace AVT::VmbAPI


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Thu Jun 6 2019 18:23:39