blob: ad43a8ee7972c1c3e505e03165dcfb36b0ff3ee4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
//
// Semaphore_VX.cpp
//
// Library: Foundation
// Package: Threading
// Module: Semaphore
//
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Semaphore_VX.h"
#error #include <sysLib.h>
namespace Poco {
SemaphoreImpl::SemaphoreImpl(int n, int max)
{
poco_assert (n >= 0 && max > 0 && n <= max);
_sem = semCCreate(SEM_Q_PRIORITY, n);
if (_sem == 0)
throw Poco::SystemException("cannot create semaphore");
}
SemaphoreImpl::~SemaphoreImpl()
{
semDelete(_sem);
}
void SemaphoreImpl::waitImpl()
{
if (semTake(_sem, WAIT_FOREVER) != OK)
throw SystemException("cannot wait for semaphore");
}
bool SemaphoreImpl::waitImpl(long milliseconds)
{
int ticks = milliseconds*sysClkRateGet()/1000;
return semTake(_sem, ticks) == OK;
}
} // namespace Poco
|