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.

99 lines
2.7 KiB

  1. //
  2. // MODULE: APIwraps.CPP
  3. //
  4. // PURPOSE: Encapsulate common blocks of API functionality within a class.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Randy Biley
  9. //
  10. // ORIGINAL DATE: 9-30-98
  11. //
  12. // NOTES:
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.0 09-30-98 RAB
  17. //
  18. #include "stdafx.h"
  19. #include "apiwraps.h"
  20. #include "event.h"
  21. #include "baseexception.h"
  22. APIwraps::APIwraps()
  23. {
  24. }
  25. APIwraps::~APIwraps()
  26. {
  27. }
  28. // Function used to handle the situation where we wish to detect sluggish or stalled objects
  29. // and log this delay before going into an infinite wait.
  30. /*static*/ bool APIwraps::WaitAndLogIfSlow(
  31. HANDLE hndl, // Handle of object to be waited on.
  32. LPCSTR srcFile, // Calling source file (__FILE__), used for logging.
  33. // LPCSTR, not LPCTSTR, because __FILE__ is a char*, not a TCHAR*
  34. int srcLine, // Calling source line (__LINE__), used for logging.
  35. DWORD TimeOutVal /*=60000*/ // Time-out interval in millisecond. After
  36. // this we log an error, then wait infinitely
  37. )
  38. {
  39. bool bRetVal= false;
  40. DWORD nWaitRetVal;
  41. CBuildSrcFileLinenoStr SrcLoc( srcFile, srcLine );
  42. nWaitRetVal= ::WaitForSingleObject( hndl, TimeOutVal );
  43. if (nWaitRetVal == WAIT_FAILED)
  44. {
  45. // very bad news, should never happen
  46. DWORD dwErr = ::GetLastError();
  47. CString strErr;
  48. strErr.Format(_T("%d"), dwErr);
  49. CBuildSrcFileLinenoStr SrcLoc3(__FILE__, __LINE__);
  50. CEvent::ReportWFEvent( SrcLoc.GetSrcFileLineStr(),
  51. SrcLoc3.GetSrcFileLineStr(),
  52. _T("Thread wait failed."),
  53. strErr,
  54. EV_GTS_ERROR_STUCK_THREAD );
  55. }
  56. else if (nWaitRetVal == WAIT_TIMEOUT)
  57. {
  58. // Initial wait timed out, note in log, and wait infinitely.
  59. CBuildSrcFileLinenoStr SrcLoc1(__FILE__, __LINE__);
  60. CEvent::ReportWFEvent( SrcLoc.GetSrcFileLineStr(),
  61. SrcLoc1.GetSrcFileLineStr(),
  62. _T("Thread wait exceeded initial timeout interval."),
  63. _T(""),
  64. EV_GTS_STUCK_THREAD );
  65. nWaitRetVal= ::WaitForSingleObject( hndl, INFINITE );
  66. // If successfully got what we were waiting for (after logging an apparent
  67. // problem), log the fact that it's ultimately OK.
  68. if (nWaitRetVal == WAIT_OBJECT_0)
  69. {
  70. CBuildSrcFileLinenoStr SrcLoc2(__FILE__, __LINE__);
  71. CEvent::ReportWFEvent( SrcLoc.GetSrcFileLineStr(),
  72. SrcLoc2.GetSrcFileLineStr(),
  73. _T("Thread infinite wait succeeded."),
  74. _T(""),
  75. EV_GTS_STUCK_THREAD );
  76. bRetVal= true;
  77. }
  78. }
  79. else
  80. {
  81. // We don't really care whether it's WAIT_OBJECT_0 or WAIT_ABANDONED.
  82. // Either way, we got what we were waiting for
  83. bRetVal= true;
  84. }
  85. return( bRetVal );
  86. }
  87. //
  88. // EOF.
  89. //