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