Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. event.cpp
  5. Abstract:
  6. SIS Groveler sync event class
  7. Authors:
  8. John Douceur, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "all.hxx"
  14. SyncEvent::SyncEvent(
  15. bool initial_state,
  16. bool manual_reset)
  17. {
  18. ASSERT(this != 0);
  19. event_handle = CreateEvent(0, manual_reset, initial_state, 0);
  20. if (event_handle == 0)
  21. {
  22. DWORD err = GetLastError();
  23. PRINT_DEBUG_MSG((_T("GROVELER: CreateEvent() failed with error %d\n"), err));
  24. throw exception_create_event;
  25. }
  26. }
  27. SyncEvent::~SyncEvent()
  28. {
  29. ASSERT(this != 0);
  30. ASSERT(event_handle != 0);
  31. int ok = CloseHandle(event_handle);
  32. if (!ok)
  33. {
  34. DWORD err = GetLastError();
  35. PRINT_DEBUG_MSG((_T("GROVELER: CloseHandle() failed with error %d\n"), err));
  36. }
  37. event_handle = 0;
  38. }
  39. bool
  40. SyncEvent::set()
  41. {
  42. ASSERT(this != 0);
  43. ASSERT(event_handle != 0);
  44. BOOL ok = SetEvent(event_handle);
  45. if (!ok)
  46. {
  47. DWORD err = GetLastError();
  48. PRINT_DEBUG_MSG((_T("GROVELER: SetEvent() failed with error %d\n"), err));
  49. }
  50. return (ok != 0);
  51. }
  52. bool
  53. SyncEvent::reset()
  54. {
  55. ASSERT(this != 0);
  56. ASSERT(event_handle != 0);
  57. BOOL ok = ResetEvent(event_handle);
  58. if (!ok)
  59. {
  60. DWORD err = GetLastError();
  61. PRINT_DEBUG_MSG((_T("GROVELER: ResetEvent() failed with error %d\n"), err));
  62. }
  63. return (ok != 0);
  64. }
  65. bool
  66. SyncEvent::wait(
  67. unsigned int timeout)
  68. {
  69. ASSERT(this != 0);
  70. ASSERT(event_handle != 0);
  71. ASSERT(signed(timeout) >= 0);
  72. DWORD result = WAIT_FOR_SINGLE_OBJECT(event_handle, timeout);
  73. if (result != WAIT_TIMEOUT && result != WAIT_OBJECT_0)
  74. {
  75. PRINT_DEBUG_MSG((_T("GROVELER: WaitForSingleObject() returned error %d\n"),
  76. result));
  77. }
  78. return (result == WAIT_OBJECT_0);
  79. }