poco/Foundation/src/Semaphore_VX.cpp
Roger Meier b0581433a7 LICENSE: add info about SPDX-License-Identifier usage and use it
fix: remove executable flag and change back to 100644 (was 100755)

Signed-off-by: Roger Meier <r.meier@siemens.com>
2014-05-14 08:38:09 +02:00

55 lines
922 B
C++

//
// Semaphore_VX.cpp
//
// $Id: //poco/1.4/Foundation/src/Semaphore_VX.cpp#1 $
//
// 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"
#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