Semaphore_VX.cpp 922 B

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