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.

144 lines
4.3 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. #include "prep.h"
  13. #include "fcomint.h"
  14. #include "fdebug.h"
  15. ///RSL
  16. #include "glbproto.h"
  17. #define faxTlog(m) DEBUGMSG(ZONE_TO, m)
  18. #define faxT2log(m) DEBUGMSG(ZONE_TIMEOUT, m)
  19. #define FILEID FILEID_TIMEOUTS
  20. /***************************************************************************
  21. Name : Timers Class
  22. Purpose : Provide for Timeouts
  23. TO -- Timeout struct
  24. startTimeout -- creates a new timeout
  25. ***************************************************************************/
  26. void startTimeOut(PThrdGlbl pTG, LPTO lpto, ULONG ulTimeout)
  27. {
  28. ///////////// ulTimeout <<= 1; // give us a little more time during debugging
  29. BG_CHK(lpto);
  30. lpto->ulStart = GetTickCount();
  31. lpto->ulTimeout = ulTimeout;
  32. lpto->ulEnd = lpto->ulStart + ulTimeout; // will wrap around as system
  33. // time nears 4Gig ms
  34. (MyDebugPrint(pTG, LOG_ALL, "StartTO: 0x%08lx --> to=0x%08lx start=0x%08lx end=0x%08lx\r\n",
  35. lpto, lpto->ulTimeout, lpto->ulStart, lpto->ulEnd));
  36. return;
  37. }
  38. BOOL checkTimeOut(PThrdGlbl pTG, LPTO lpto)
  39. {
  40. // if it returns FALSE, caller must return FALSE immediately
  41. // (after cleaning up, as appropriate).
  42. // SWORD swRet;
  43. ULONG ulTime;
  44. BG_CHK(lpto);
  45. ulTime = GetTickCount();
  46. //// if(fVerbose3)
  47. //// (MyDebugPrint(pTG, "CheckTO: 0x%08lx --> to=0x%08lx start=0x%08lx end=0x%08lx CURR=0x%08lx\r\n",
  48. //// lpto, lpto->ulTimeout, lpto->ulStart, lpto->ulEnd, ulTime));
  49. if(lpto->ulTimeout == 0)
  50. {
  51. goto out;
  52. }
  53. else if(lpto->ulEnd >= lpto->ulStart)
  54. {
  55. if(ulTime >= lpto->ulStart && ulTime <= lpto->ulEnd)
  56. return TRUE;
  57. else
  58. goto out;
  59. }
  60. else // ulEnd wrapped around!!
  61. {
  62. ERRMSG(("<<ERROR>> CheckTO WRAPPED!!: 0x%04x --> to=0x%08lx start=0x%08lx end=0x%08lx time=0x%08lx\r\n",
  63. lpto, lpto->ulTimeout, lpto->ulStart, lpto->ulEnd, ulTime));
  64. if(ulTime >= lpto->ulStart || ulTime <= lpto->ulEnd)
  65. return TRUE;
  66. else
  67. goto out;
  68. }
  69. out:
  70. faxT2log(("CheckTO--TIMEOUT!: 0x%04x --> to=0x%08lx start=0x%08lx end=0x%08lx CURR=0x%08lx\r\n",
  71. lpto, lpto->ulTimeout, lpto->ulStart, lpto->ulEnd, ulTime));
  72. return FALSE;
  73. }
  74. // this will return garbage values if
  75. ULONG leftTimeOut(PThrdGlbl pTG, LPTO lpto)
  76. {
  77. ULONG ulTime;
  78. BG_CHK(lpto);
  79. ulTime = GetTickCount();
  80. if(lpto->ulTimeout == 0)
  81. return 0;
  82. else if(lpto->ulEnd >= lpto->ulStart)
  83. {
  84. if(ulTime >= lpto->ulStart && ulTime <= lpto->ulEnd)
  85. return (lpto->ulEnd - ulTime);
  86. else
  87. return 0;
  88. }
  89. else
  90. {
  91. if(ulTime >= lpto->ulStart || ulTime <= lpto->ulEnd)
  92. return (lpto->ulEnd - ulTime); // in unsigned arithmetic this
  93. // works correctly even if End<Time
  94. else
  95. return 0;
  96. }
  97. }