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.

94 lines
1.5 KiB

  1. //
  2. // VERY USEFUL TIMER ROUTINES
  3. //
  4. BOOL
  5. RtCreateTimer(IN PHANDLE TimerHandlep)
  6. {
  7. OBJECT_ATTRIBUTES ObjA;
  8. NTSTATUS Status;
  9. InitializeObjectAttributes(&ObjA, NULL, 0, NULL, NULL);
  10. Status = NtCreateTimer(TimerHandlep, TIMER_ALL_ACCESS, &ObjA);
  11. if (!NT_SUCCESS(Status)) {
  12. SS_PRINT(("Failed to create timer: %X\n", Status));
  13. return TRUE;
  14. }
  15. return FALSE;
  16. }
  17. BOOL
  18. RtDestroyTimer(IN HANDLE TimerHandle)
  19. {
  20. NTSTATUS Status;
  21. Status = NtClose(TimerHandle);
  22. if (!NT_SUCCESS(Status)) {
  23. SS_PRINT(("Failed to create timer: %X\n", Status));
  24. return TRUE;
  25. }
  26. return FALSE;
  27. }
  28. BOOL
  29. RtSetTimer(
  30. IN HANDLE TimerHandle,
  31. IN ULONG MillisecondsToExpire,
  32. IN PTIMER_APC_ROUTINE TimerRoutine,
  33. IN PVOID Context
  34. )
  35. {
  36. LARGE_INTEGER TimerDueTime;
  37. NTSTATUS NtStatus;
  38. //
  39. // Figure out the timeout.
  40. //
  41. TimerDueTime.QuadPart = Int32x32To64( MillisecondsToExpire, -10000 );
  42. //
  43. // Set the timer to go off when it expires.
  44. //
  45. NtStatus = NtSetTimer(TimerHandle,
  46. &TimerDueTime,
  47. TimerRoutine,
  48. Context,
  49. NULL);
  50. if (!NT_SUCCESS(NtStatus)) {
  51. SS_PRINT(("RtSetTimer: Failed to set timer: 0x%x\n", NtStatus));
  52. SS_ASSERT(FALSE);
  53. return TRUE;
  54. }
  55. return FALSE;
  56. }
  57. BOOL
  58. RtCancelTimer(
  59. IN HANDLE TimerHandle;
  60. )
  61. {
  62. NTSTATUS NtStatus;
  63. NtStatus = NtCancelTimer(TimerHandle, NULL);
  64. if (!NT_SUCCESS(NtStatus)) {
  65. SS_PRINT(("RtCancelTimer: Failed to cancel timer: 0x%x\n", NtStatus));
  66. return TRUE;
  67. }
  68. return FALSE;
  69. }