Event_WIN32.cpp 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Event_WIN32.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Event_WIN32.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_WIN32.h"
  16. namespace Poco {
  17. EventImpl::EventImpl(bool autoReset)
  18. {
  19. _event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL);
  20. if (!_event)
  21. throw SystemException("cannot create event");
  22. }
  23. EventImpl::~EventImpl()
  24. {
  25. CloseHandle(_event);
  26. }
  27. void EventImpl::waitImpl()
  28. {
  29. switch (WaitForSingleObject(_event, INFINITE))
  30. {
  31. case WAIT_OBJECT_0:
  32. return;
  33. default:
  34. throw SystemException("wait for event failed");
  35. }
  36. }
  37. bool EventImpl::waitImpl(long milliseconds)
  38. {
  39. switch (WaitForSingleObject(_event, milliseconds + 1))
  40. {
  41. case WAIT_TIMEOUT:
  42. return false;
  43. case WAIT_OBJECT_0:
  44. return true;
  45. default:
  46. throw SystemException("wait for event failed");
  47. }
  48. }
  49. } // namespace Poco