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.

116 lines
3.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: waitmult.hxx
  7. //
  8. // Contents: Encapsulates a Win32 WaitForMultipleObjects
  9. //
  10. // History: 04-Aug-94 DwightKr Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. //+-------------------------------------------------------------------------
  15. //
  16. // Class: CWaitForMultipleObjects
  17. //
  18. // Purpose: Constructor
  19. //
  20. // History: 07-Jun-94 DwightKr Created
  21. //
  22. //--------------------------------------------------------------------------
  23. class CWaitForMultipleObjects
  24. {
  25. public :
  26. inline CWaitForMultipleObjects(ULONG cMaxHandles);
  27. ~CWaitForMultipleObjects() { delete [] _pHandles; }
  28. inline void AddEvent( HANDLE hEvent );
  29. inline HANDLE Get( DWORD i ) const;
  30. inline DWORD Wait( DWORD dwTimeout );
  31. void ResetCount() { _cNumHandles = 0; }
  32. private:
  33. HANDLE * _pHandles; // Doesn't own handles in _pHandles
  34. ULONG _cMaxHandles;
  35. ULONG _cNumHandles;
  36. };
  37. //+-------------------------------------------------------------------------
  38. //
  39. // Method: CWaitForMultipleObjects::CWaitForMultipleObjects, public
  40. //
  41. // Purpose: Constructor
  42. //
  43. // History: 07-Jun-94 DwightKr Created
  44. //
  45. //--------------------------------------------------------------------------
  46. inline CWaitForMultipleObjects::CWaitForMultipleObjects( ULONG cMaxHandles )
  47. : _cMaxHandles(cMaxHandles),
  48. _cNumHandles(0),
  49. _pHandles(0)
  50. {
  51. _pHandles = new HANDLE[_cMaxHandles];
  52. }
  53. //+-------------------------------------------------------------------------
  54. //
  55. // Method: CWaitForMultipleObjects::AddEvent, public
  56. //
  57. // Purpose: Adds an handle to be waited on
  58. //
  59. // Arguments: [hEvent] -- Handle to add
  60. //
  61. // History: 07-Jun-94 DwightKr Created
  62. //
  63. //--------------------------------------------------------------------------
  64. inline void CWaitForMultipleObjects::AddEvent( HANDLE hEvent )
  65. {
  66. Win4Assert( _cNumHandles < _cMaxHandles );
  67. _pHandles[ _cNumHandles ] = hEvent;
  68. _cNumHandles++;
  69. }
  70. //+-------------------------------------------------------------------------
  71. //
  72. // Method: CWaitForMultipleObjects::Wait, public
  73. //
  74. // Purpose: Waits for one of the handles to be signalled, or timeout
  75. //
  76. // History: 07-Jun-94 DwightKr Created
  77. //
  78. //--------------------------------------------------------------------------
  79. inline DWORD CWaitForMultipleObjects::Wait( DWORD dwTimeout )
  80. {
  81. return WaitForMultipleObjects( _cNumHandles,
  82. _pHandles,
  83. FALSE,
  84. dwTimeout );
  85. }
  86. //+-------------------------------------------------------------------------
  87. //
  88. // Method: CWaitForMultipleObjects::Get, public
  89. //
  90. // Synopsis: Retrieves the I-th handle
  91. //
  92. // Arguments: [i] -- i
  93. //
  94. // Returns: The I-th handle
  95. //
  96. // History: 23-Jun-98 KyleP Created
  97. //
  98. //--------------------------------------------------------------------------
  99. inline HANDLE CWaitForMultipleObjects::Get( DWORD i ) const
  100. {
  101. Win4Assert( i < _cNumHandles );
  102. return _pHandles[ i ];
  103. }