Event_VX.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Event_POSIX.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Event_VX.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Threading
  8. // Module: Event
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Event_VX.h"
  16. #include <sysLib.h>
  17. namespace Poco {
  18. EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
  19. {
  20. _sem = semCCreate(SEM_Q_PRIORITY, 0);
  21. if (_sem == 0)
  22. throw Poco::SystemException("cannot create event");
  23. }
  24. EventImpl::~EventImpl()
  25. {
  26. semDelete(_sem);
  27. }
  28. void EventImpl::setImpl()
  29. {
  30. if (_auto)
  31. {
  32. if (semGive(_sem) != OK)
  33. throw SystemException("cannot set event");
  34. }
  35. else
  36. {
  37. _state = true;
  38. if (semFlush(_sem) != OK)
  39. throw SystemException("cannot set event");
  40. }
  41. }
  42. void EventImpl::resetImpl()
  43. {
  44. _state = false;
  45. }
  46. void EventImpl::waitImpl()
  47. {
  48. if (!_state)
  49. {
  50. if (semTake(_sem, WAIT_FOREVER) != OK)
  51. throw SystemException("cannot wait for event");
  52. }
  53. }
  54. bool EventImpl::waitImpl(long milliseconds)
  55. {
  56. if (!_state)
  57. {
  58. int ticks = milliseconds*sysClkRateGet()/1000;
  59. return semTake(_sem, ticks) == OK;
  60. }
  61. else return true;
  62. }
  63. } // namespace Poco