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.

111 lines
3.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-2000.
  5. //
  6. // File: timlimit.hxx
  7. //
  8. // Contents: Class to monitor execution time of a query
  9. //
  10. // Classes: CTimeLimit
  11. //
  12. // History: 09 Jul 1996 AlanW Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CTimeLimit
  19. //
  20. // Purpose: Monitor elapsed execution time of a query
  21. //
  22. // History: 09 Jul 1996 AlanW Created
  23. //
  24. //----------------------------------------------------------------------------
  25. class CTimeLimit
  26. {
  27. public:
  28. CTimeLimit( ULONG ulMaxExecutionTime, ULONG ulMaxTimeOverride );
  29. CTimeLimit( CTimeLimit & TimeLim ) :
  30. _ullExecutionTimeLimit( TimeLim._ullExecutionTimeLimit ),
  31. _ullBaselineTime( TimeLim._ullBaselineTime ),
  32. _fDisableCheck( TimeLim._fDisableCheck )
  33. { }
  34. void SetBaselineTime( );
  35. inline void SetMaxOverrideTime( ULONG ulMaxTimeOverride );
  36. BOOL CheckExecutionTime( ULONGLONG *pullTimeslice = 0 );
  37. void DisableCheck() { _fDisableCheck = TRUE; }
  38. void EnableCheck() { _fDisableCheck = FALSE; }
  39. BOOL CheckDisabled() { return _fDisableCheck; }
  40. void SetExecutionTime( ULONGLONG ullExecutionTimeLimit ) { _ullExecutionTimeLimit = ullExecutionTimeLimit; }
  41. BOOL IsTimedOut( ) { return _fDisableCheck ? FALSE : ( _ullExecutionTimeLimit == 0 ); }
  42. BOOL IsNoTimeOut( ) { return ( _UI64_MAX == _ullExecutionTimeLimit ); }
  43. private:
  44. ULONGLONG _ullExecutionTimeLimit;// Execution time limit (100 nsec)
  45. ULONGLONG _ullBaselineTime; // Execution time snapshot (100 nsec)
  46. BOOL _fDisableCheck;
  47. };
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Member: CTimeLimit::SetMaxOverrideTime, public
  51. //
  52. // Synopsis: Set a high-water mark for time limit
  53. //
  54. // Arguments: [ulMaxTimeOverride] - upper bound on ulExecutionTimeLimit (in msec)
  55. //
  56. // History: 22-Jan-1998 KyleP Created
  57. //
  58. // Note: Calling this method *after* the first call to CheckExecutionTime
  59. // will result in some time potentially being uncounted between
  60. // construction and the call to SetMaxOverrideTime.
  61. //
  62. //----------------------------------------------------------------------------
  63. inline void CTimeLimit::SetMaxOverrideTime( ULONG ulMaxTimeOverride )
  64. {
  65. #if CIDBG == 1
  66. //
  67. // Undo artificial increment, just to make computation more straightforward.
  68. //
  69. if ( ciInfoLevel > 7 || vqInfoLevel > 7)
  70. {
  71. if (_UI64_MAX != _ullExecutionTimeLimit)
  72. _ullExecutionTimeLimit /= 50;
  73. }
  74. #endif
  75. if ( ulMaxTimeOverride > 0 )
  76. _ullExecutionTimeLimit = min( _ullExecutionTimeLimit, ulMaxTimeOverride * 10000 );
  77. #if DBG || CIDBG
  78. //
  79. // Debugs are time-costly...
  80. //
  81. if ( ciInfoLevel > 7 || vqInfoLevel > 7 )
  82. {
  83. if (_UI64_MAX != _ullExecutionTimeLimit)
  84. _ullExecutionTimeLimit *= 50;
  85. }
  86. #endif // DBG || CIDBG
  87. }