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.

120 lines
2.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: eventwrp.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. Microsoft OS/2 LAN Manager
  12. Copyright(c) Microsoft Corp., 1990
  13. -------------------------------------------------------------------- */
  14. /* --------------------------------------------------------------------
  15. File: mutex.cxx
  16. Description:
  17. This file contains the system independent mutex class for NT.
  18. History:
  19. mikemon ??-??-?? The beginning.
  20. mikemon 12-31-90 Upgraded the comments.
  21. -------------------------------------------------------------------- */
  22. #include <precomp.hxx>
  23. EVENT::EVENT (
  24. IN OUT RPC_STATUS PAPI * RpcStatus,
  25. IN int ManualReset,
  26. IN BOOL fDelayInit
  27. )
  28. {
  29. EventHandle = NULL;
  30. // DelayInit events are auto reset
  31. ASSERT(ManualReset == FALSE || fDelayInit == FALSE);
  32. if (!fDelayInit && *RpcStatus == RPC_S_OK )
  33. {
  34. EventHandle = CreateEvent(NULL, ManualReset, 0, NULL);
  35. if ( EventHandle != NULL )
  36. {
  37. LogEvent(SU_EVENT, EV_CREATE, EventHandle, 0, 0, 1, 2);
  38. *RpcStatus = RPC_S_OK;
  39. }
  40. else
  41. {
  42. *RpcStatus = RPC_S_OUT_OF_MEMORY;
  43. }
  44. }
  45. }
  46. EVENT::~EVENT (
  47. )
  48. {
  49. if ( EventHandle )
  50. {
  51. LogEvent(SU_EVENT, EV_DELETE, EventHandle, 0, 0, 1, 2);
  52. BOOL bResult;
  53. bResult = CloseHandle(EventHandle);
  54. ASSERT(bResult != 0);
  55. }
  56. }
  57. int
  58. EVENT::Wait (
  59. long timeout
  60. )
  61. {
  62. DWORD result;
  63. if (NULL == EventHandle)
  64. {
  65. InitializeEvent();
  66. }
  67. result = WaitForSingleObject(EventHandle, timeout);
  68. if (result == WAIT_TIMEOUT)
  69. return(1);
  70. return(0);
  71. }
  72. void
  73. EVENT::InitializeEvent (
  74. )
  75. // Used when fDelayInit is TRUE in the c'tor.
  76. {
  77. if (EventHandle)
  78. {
  79. return;
  80. }
  81. HANDLE event = CreateEvent(0, FALSE, FALSE, 0);
  82. if (event)
  83. {
  84. if (InterlockedCompareExchangePointer(&EventHandle, event, 0) != 0)
  85. {
  86. CloseHandle(event);
  87. }
  88. return;
  89. }
  90. // Can't allocate an event.
  91. RpcRaiseException(RPC_S_OUT_OF_RESOURCES);
  92. }