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.

96 lines
2.7 KiB

  1. /***************************************************************************
  2. Name : TIMEOUTS.C
  3. Comment : Various support functions
  4. Revision Log
  5. Num Date Name Description
  6. --- -------- ---------- -----------------------------------------------
  7. 001 12/18/91 arulm Commenting it for the first time. This is the
  8. "stable" DOS version from which the Windows code
  9. will be derived. This file should not change
  10. for Windows
  11. ***************************************************************************/
  12. #define USE_DEBUG_CONTEXT DEBUG_CONTEXT_T30_COMM
  13. #include "prep.h"
  14. #include "fcomint.h"
  15. #include "fdebug.h"
  16. ///RSL
  17. #include "glbproto.h"
  18. /***************************************************************************
  19. Name : Timers Class
  20. Purpose : Provide for Timeouts
  21. TO -- Timeout struct
  22. startTimeout -- creates a new timeout
  23. ***************************************************************************/
  24. void startTimeOut(PThrdGlbl pTG, LPTO lpto, ULONG ulTimeout)
  25. {
  26. lpto->ulStart = GetTickCount();
  27. lpto->ulTimeout = ulTimeout;
  28. lpto->ulEnd = lpto->ulStart + ulTimeout; // will wrap around as system
  29. }
  30. BOOL checkTimeOut(PThrdGlbl pTG, LPTO lpto)
  31. {
  32. // if it returns FALSE, caller must return FALSE immediately
  33. // (after cleaning up, as appropriate).
  34. ULONG ulTime;
  35. ulTime = GetTickCount();
  36. if(lpto->ulTimeout == 0)
  37. {
  38. goto out;
  39. }
  40. else if(lpto->ulEnd >= lpto->ulStart)
  41. {
  42. if(ulTime >= lpto->ulStart && ulTime <= lpto->ulEnd)
  43. return TRUE;
  44. else
  45. goto out;
  46. }
  47. else // ulEnd wrapped around!!
  48. {
  49. if(ulTime >= lpto->ulStart || ulTime <= lpto->ulEnd)
  50. return TRUE;
  51. else
  52. goto out;
  53. }
  54. out:
  55. return FALSE;
  56. }
  57. // this will return garbage values if
  58. ULONG leftTimeOut(PThrdGlbl pTG, LPTO lpto)
  59. {
  60. ULONG ulTime;
  61. ulTime = GetTickCount();
  62. if(lpto->ulTimeout == 0)
  63. return 0;
  64. else if(lpto->ulEnd >= lpto->ulStart)
  65. {
  66. if(ulTime >= lpto->ulStart && ulTime <= lpto->ulEnd)
  67. return (lpto->ulEnd - ulTime);
  68. else
  69. return 0;
  70. }
  71. else
  72. {
  73. if(ulTime >= lpto->ulStart || ulTime <= lpto->ulEnd)
  74. return (lpto->ulEnd - ulTime); // in unsigned arithmetic this works correctly even if End<Time
  75. else
  76. return 0;
  77. }
  78. }