soui
5.0.0.1
Soui5 Doc
Loading...
Searching...
No Matches
SSemaphore.cpp
1
#include <helper/SSemaphore.h>
2
#include <windows.h>
3
#include <cerrno>
4
5
SNSBEGIN
6
7
class
SemaphorePrivate
8
{
9
public
:
10
HANDLE _hsem;
11
};
12
13
SSemaphore::SSemaphore
() :
14
_private(*(new SemaphorePrivate()))
15
{
16
_private._hsem = ::CreateSemaphore(NULL, 0, 65535
/* we need to discuss this max value*/
, NULL);
17
}
18
19
SSemaphore::~SSemaphore
()
20
{
21
::CloseHandle(_private._hsem);
22
delete
&_private;
23
}
24
25
int
SSemaphore::wait
()
26
{
27
DWORD ret = ::WaitForSingleObject (_private._hsem, INFINITE);
28
29
if
( ret == WAIT_OBJECT_0)
30
{
31
return
RETURN_OK;
32
}
33
34
return
RETURN_ERROR;
// This is a blocking wait, so any value other than WAIT_OBJECT_0 indicates an error!
35
}
36
37
int
SSemaphore::wait
(
unsigned
int
msec)
38
{
39
DWORD ret = ::WaitForSingleObject (_private._hsem, msec);
40
41
if
( ret == WAIT_OBJECT_0)
42
{
43
return
RETURN_OK;
44
}
45
46
// This is a timed wait, so WAIT_TIMEOUT value must be checked!
47
if
( ret == WAIT_TIMEOUT )
48
{
49
return
RETURN_TIMEOUT;
50
}
51
52
return
RETURN_ERROR;
53
}
54
55
void
SSemaphore::notify
()
56
{
57
::ReleaseSemaphore(_private._hsem, 1, NULL);
58
}
59
SNSEND
SSemaphore::wait
int wait()
Waits indefinitely for the semaphore to be notified.
Definition
SSemaphore.cpp:25
SSemaphore::~SSemaphore
virtual ~SSemaphore()
Destructor. Cleans up the semaphore resources.
Definition
SSemaphore.cpp:19
SSemaphore::notify
void notify()
Notifies the semaphore.
Definition
SSemaphore.cpp:55
SSemaphore::SSemaphore
SSemaphore()
Default constructor. Initializes the semaphore.
Definition
SSemaphore.cpp:13
utilities
src
helper
SSemaphore.cpp
Generated by
1.13.2