Mutex_VX.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // Mutex_VX.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Mutex_VX.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Threading
  8. // Module: Mutex
  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/Mutex_VX.h"
  16. #include <sysLib.h>
  17. namespace Poco {
  18. MutexImpl::MutexImpl()
  19. {
  20. _sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
  21. if (_sem == 0)
  22. throw Poco::SystemException("cannot create mutex");
  23. }
  24. MutexImpl::MutexImpl(bool fast)
  25. {
  26. if (fast)
  27. {
  28. _sem = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
  29. }
  30. else
  31. {
  32. _sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
  33. }
  34. if (_sem == 0)
  35. throw Poco::SystemException("cannot create mutex");
  36. }
  37. MutexImpl::~MutexImpl()
  38. {
  39. semDelete(_sem);
  40. }
  41. bool MutexImpl::tryLockImpl(long milliseconds)
  42. {
  43. int ticks = milliseconds*sysClkRateGet()/1000;
  44. return semTake(_sem, ticks) == OK;
  45. }
  46. FastMutexImpl::FastMutexImpl(): MutexImpl(true)
  47. {
  48. }
  49. FastMutexImpl::~FastMutexImpl()
  50. {
  51. }
  52. } // namespace Poco