include
VimbaCPP
Source
Semaphore.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: Semaphore.cpp
10
11
Description: Implementation of an semaphore class.
12
Intended for use in the implementation of Vimba CPP API.
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/Source/Semaphore.h
>
32
#include <
VimbaCPP/Include/LoggerDefines.h
>
33
34
namespace
AVT
{
35
namespace
VmbAPI {
36
37
Semaphore::Semaphore
(
int
nInit,
int
nMax )
38
#ifdef WIN32
39
: m_hSemaphore( NULL )
40
#endif
41
{
42
#ifdef WIN32
43
m_hSemaphore = CreateSemaphore( NULL, nInit, nMax, NULL );
44
if
( NULL == m_hSemaphore )
45
{
46
LOG_FREE_TEXT
(
"Could not create semaphore."
);
47
throw
std::bad_alloc();
48
}
49
#else
50
sem_init( &m_Semaphore,
false
, (
unsigned
int
)nInit );
51
#endif
52
}
53
54
Semaphore::Semaphore
(
const
Semaphore
& )
55
{
56
// No compiler generated copy ctor
57
}
58
59
Semaphore
&
Semaphore::operator=
(
const
Semaphore
& )
60
{
61
// No assignment operator
62
return
*
this
;
63
}
64
65
Semaphore::~Semaphore
()
66
{
67
#ifdef WIN32
68
CloseHandle( m_hSemaphore );
69
#else
70
sem_destroy( &
m_Semaphore
);
71
#endif
72
}
73
74
void
Semaphore::Acquire
()
75
{
76
#ifdef WIN32
77
WaitForSingleObject( m_hSemaphore, INFINITE );
78
#else
79
sem_wait( &
m_Semaphore
);
80
#endif
81
}
82
83
void
Semaphore::Release
()
84
{
85
#ifdef WIN32
86
ReleaseSemaphore( m_hSemaphore, 1, NULL );
87
#else
88
sem_post( &
m_Semaphore
);
89
#endif
90
}
91
92
}
//namespace VmbAPI
93
}
//namespace AVT
AVT::VmbAPI::Semaphore::Acquire
void Acquire()
Definition:
Semaphore.cpp:74
AVT
Definition:
AncillaryData.h:35
AVT::VmbAPI::Semaphore::operator=
Semaphore & operator=(const Semaphore &)
Definition:
Semaphore.cpp:59
AVT::VmbAPI::Semaphore
Definition:
Semaphore.h:43
LOG_FREE_TEXT
#define LOG_FREE_TEXT(txt)
Definition:
LoggerDefines.h:56
AVT::VmbAPI::Semaphore::m_Semaphore
sem_t m_Semaphore
Definition:
Semaphore.h:61
LoggerDefines.h
AVT::VmbAPI::Semaphore::Semaphore
Semaphore(int nInit=0, int nMax=1)
Definition:
Semaphore.cpp:37
Semaphore.h
AVT::VmbAPI::Semaphore::~Semaphore
~Semaphore()
Definition:
Semaphore.cpp:65
AVT::VmbAPI::Semaphore::Release
void Release()
Definition:
Semaphore.cpp:83
avt_vimba_camera
Author(s): Allied Vision Technologies, Miquel Massot
autogenerated on Sat Jun 3 2023 02:14:12