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.

141 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. timer.cpp
  5. Abstract:
  6. Contains:
  7. Routines for timer operations
  8. Environment:
  9. User Mode - Win32
  10. History:
  11. 1. 14-Feb-2000 -- File creation (based on Ilya Kleyman (ilyak)
  12. previous work by AjayCh)
  13. --*/
  14. #include "stdafx.h"
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // //
  17. // Global Variables //
  18. // //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // TIMER_PROCESSOR ------------------------------------------------------------------
  21. /*
  22. * This function is passed as the callback in the
  23. * CreateTimerQueueTimer() function
  24. */
  25. // static
  26. void WINAPI TimeoutCallback (
  27. IN PVOID Context,
  28. IN BOOLEAN TimerFired)
  29. {
  30. TIMER_PROCESSOR *pTimerProcessor = (TIMER_PROCESSOR *) Context;
  31. pTimerProcessor->TimerCallback();
  32. // At this point the timer would have been canceled because
  33. // this is a one shot timer (no period)
  34. }
  35. /*++
  36. Routine Description:
  37. Create a timer.
  38. Arguments:
  39. Return Values:
  40. if Success the caller should increase the ref count.
  41. --*/
  42. DWORD TIMER_PROCESSOR::TimprocCreateTimer (
  43. IN DWORD TimeoutValue)
  44. {
  45. HRESULT Result;
  46. if (m_TimerHandle) {
  47. DebugF (_T("H323: timer is already pending, cannot create new timer.\n"));
  48. return E_FAIL;
  49. }
  50. IncrementLifetimeCounter ();
  51. if (CreateTimerQueueTimer(&m_TimerHandle,
  52. NATH323_TIMER_QUEUE,
  53. TimeoutCallback,
  54. this,
  55. TimeoutValue,
  56. 0, // One shot timer
  57. WT_EXECUTEINIOTHREAD)) {
  58. assert (m_TimerHandle);
  59. Result = S_OK;
  60. }
  61. else {
  62. Result = GetLastResult();
  63. DecrementLifetimeCounter ();
  64. }
  65. return Result;
  66. }
  67. /*++
  68. Routine Description:
  69. Cancel the timer if there is one. Otherwise simply return.
  70. Arguments:
  71. Return Values:
  72. --*/
  73. // If Canceling the timer fails this means that the
  74. // timer callback could be pending. In this scenario,
  75. // the timer callback could execute later and so we
  76. // should not release the refcount on the TIMER_CALLBACK
  77. // The refcount will be released in the TimerCallback().
  78. // Release the ref count if callback is NOT pending.
  79. DWORD TIMER_PROCESSOR::TimprocCancelTimer (void) {
  80. HRESULT HResult = S_OK;
  81. if (m_TimerHandle != NULL) {
  82. if (DeleteTimerQueueTimer(NATH323_TIMER_QUEUE, m_TimerHandle, NULL)) {
  83. DecrementLifetimeCounter ();
  84. }
  85. else {
  86. HResult = GetLastError ();
  87. }
  88. m_TimerHandle = NULL;
  89. }
  90. return HResult;
  91. }