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.

91 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. timindex.asm
  5. Abstract:
  6. This module implements the code necessary to compute the timer table
  7. index for a timer.
  8. Author:
  9. David N. Cutler (davec) 16-Jun-2000
  10. Environment:
  11. Any mode.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. ULONG
  16. KiComputeTimerTableIndex (
  17. IN LARGE_INTEGER Interval,
  18. IN LARGE_INTEGER CurrentTime,
  19. IN PKTIMER Timer
  20. )
  21. /*++
  22. Routine Description:
  23. This function computes the timer table index for the specified timer
  24. object and stores the due time in the timer object.
  25. N.B. The interval parameter is guaranteed to be negative since it is
  26. expressed as relative time.
  27. The formula for due time calculation is:
  28. Due Time = Current Time - Interval
  29. The formula for the index calculation is:
  30. Index = (Due Time / Maximum time) & (Table Size - 1)
  31. The time increment division is performed using reciprocal multiplication.
  32. Arguments:
  33. Interval - Supplies the relative time at which the timer is to
  34. expire.
  35. CurrentCount - Supplies the current system tick count.
  36. Timer - Supplies a pointer to a dispatch object of type timer.
  37. Return Value:
  38. The time table index is returned as the function value and the due
  39. time is stored in the timer object.
  40. --*/
  41. {
  42. LONG64 DueTime;
  43. LONG64 HighTime;
  44. ULONG Index;
  45. //
  46. // Compute the due time of the timer.
  47. //
  48. DueTime = CurrentTime.QuadPart - Interval.QuadPart;
  49. Timer->DueTime.QuadPart = DueTime;
  50. //
  51. // Compute the timer table index.
  52. //
  53. HighTime = MultiplyHigh(DueTime, KiTimeIncrementReciprocal.QuadPart);
  54. Index = (ULONG)(HighTime >> KiTimeIncrementShiftCount);
  55. return (Index & (TIMER_TABLE_SIZE - 1));
  56. }