Leaked source code of windows server 2003
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.

89 lines
1.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: signal.cxx
  7. //
  8. // Contents: Signal class implementation
  9. //
  10. // Classes: CSignal
  11. //
  12. // History: 29-Sep-93 CarlH Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <windows.h>
  16. #include "signal.hxx"
  17. #pragma hdrstop
  18. CSignal::CSignal(WCHAR const *pwszName) :
  19. _pwszName(new WCHAR[wcslen(pwszName) + 1]),
  20. _hevent(0)
  21. {
  22. wcscpy(_pwszName, pwszName);
  23. }
  24. CSignal::~CSignal(void)
  25. {
  26. delete _pwszName;
  27. if (_hevent != 0)
  28. {
  29. CloseHandle(_hevent);
  30. }
  31. }
  32. DWORD CSignal::Wait(DWORD dwTimeout)
  33. {
  34. DWORD stat = 0;
  35. if (_hevent == 0)
  36. {
  37. _hevent = CreateEvent(NULL, TRUE, FALSE, _pwszName);
  38. if (_hevent == 0)
  39. {
  40. stat = GetLastError();
  41. }
  42. }
  43. if (stat == 0)
  44. {
  45. stat = WaitForSingleObject(_hevent, dwTimeout);
  46. if (stat == 0)
  47. {
  48. ResetEvent(_hevent);
  49. }
  50. }
  51. return (stat);
  52. }
  53. DWORD CSignal::Signal(void)
  54. {
  55. DWORD stat = 0;
  56. if (_hevent == 0)
  57. {
  58. _hevent = CreateEvent(NULL, TRUE, FALSE, _pwszName);
  59. if (_hevent == 0)
  60. {
  61. stat = GetLastError();
  62. }
  63. }
  64. if (stat == 0)
  65. {
  66. if (!SetEvent(_hevent))
  67. {
  68. stat = GetLastError();
  69. }
  70. }
  71. return (stat);
  72. }