Semaphore.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:        Semaphore.cpp
00010 
00011   Description: Implementation of an semaphore class.
00012                (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/Source/Semaphore.h>
00032 #include <VimbaCPP/Include/LoggerDefines.h>
00033 
00034 namespace AVT {
00035 namespace VmbAPI {
00036 
00037 Semaphore::Semaphore( int nInit, int nMax )
00038 #ifdef WIN32
00039     :   m_hSemaphore( NULL )
00040 #endif
00041 {
00042 #ifdef WIN32
00043     m_hSemaphore = CreateSemaphore( NULL, nInit, nMax, NULL );
00044     if( NULL == m_hSemaphore )
00045     {
00046         LOG_FREE_TEXT( "Could not create semaphore." );
00047         throw std::bad_alloc();
00048     }
00049 #else
00050     sem_init( &m_Semaphore, false, (unsigned int)nInit );
00051 #endif
00052 }
00053 
00054 Semaphore::Semaphore( const Semaphore& )
00055 {
00056     // No compiler generated copy ctor
00057 }
00058 
00059 Semaphore& Semaphore::operator=( const Semaphore& )
00060 {
00061     // No assignment operator
00062     return *this;
00063 }
00064 
00065 Semaphore::~Semaphore()
00066 {  
00067 #ifdef WIN32
00068     CloseHandle( m_hSemaphore );
00069 #else
00070     sem_destroy( &m_Semaphore );
00071 #endif
00072 }
00073 
00074 void Semaphore::Acquire()
00075 {
00076 #ifdef WIN32
00077     WaitForSingleObject( m_hSemaphore, INFINITE );
00078 #else
00079     sem_wait( &m_Semaphore );
00080 #endif
00081 }
00082 
00083 void Semaphore::Release()
00084 {
00085 #ifdef WIN32
00086     ReleaseSemaphore( m_hSemaphore, 1, NULL );
00087 #else
00088     sem_post( &m_Semaphore );
00089 #endif
00090 }
00091 
00092 } //namespace VmbAPI
00093 } //namespace AVT


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