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.

202 lines
5.2 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. //
  3. // timer.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // Timer management header
  6. //
  7. // 01/07/97 Steve Cobb
  8. //
  9. // This interface encapsulates the queuing of multiple timer events onto a
  10. // single NDIS timer.
  11. #ifndef _TIMER_H_
  12. #define _TIMER_H_
  13. //-----------------------------------------------------------------------------
  14. // Data structures
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations.
  17. //
  18. typedef struct _TIMERQ TIMERQ;
  19. typedef struct _TIMERQITEM TIMERQITEM;
  20. typedef enum _TIMERQEVENT TIMERQEVENT;
  21. // Timer queue event handler. 'PTqi' and 'pContext' are the timer event
  22. // descriptor and user context passed to TimerQScheduleItem. 'Event' is the
  23. // timer event code indicating whether the timer expired, was cancelled, or
  24. // the queue was terminated.
  25. //
  26. // The "cancel" event is never generated internally, but only by a user call
  27. // to TimerQCancelItem, thus user may require specific locks be held for
  28. // "cancel" events. User cannot require than specific locks be held for
  29. // "expire" or "terminate" events as these may be generated internally. User
  30. // should pay attention to the return codes of TimerQCancelItem and
  31. // TimerQTerminateItem calls, as it will occassionally be impossible to stop
  32. // an "expire" event that has not yet been processed from occurring.
  33. //
  34. typedef
  35. VOID
  36. (*PTIMERQEVENT)(
  37. IN TIMERQITEM* pTqi,
  38. IN VOID* pContext,
  39. IN TIMERQEVENT event );
  40. // Timer queue termination completion handler. 'PTimerQ' is the timer queue
  41. // descriptor. 'PContext' is user's context as passed to TimerQTerminate.
  42. // Caller must not free or reuse the TIMERQ before this routine is called.
  43. //
  44. typedef
  45. VOID
  46. (*PTIMERQTERMINATECOMPLETE)(
  47. IN TIMERQ* pTimerQ,
  48. IN VOID* pContext );
  49. // Timer queue descriptor. All access should be via the TimerQ* interface.
  50. // There is no reason user should look inside. All necessary locking is
  51. // handled internally.
  52. //
  53. typedef struct
  54. _TIMERQ
  55. {
  56. // Set to MTAG_TIMERQ when the block is valid and to MTAG_FREED when no
  57. // longer valid.
  58. //
  59. LONG ulTag;
  60. // Head of a double-linked list of "ticking" TIMERQITEMs. The list is
  61. // sorted by time to expiration with the earliest expiration at the head
  62. // of the list. The list is protected by 'lock'.
  63. //
  64. LIST_ENTRY listItems;
  65. // Caller's terminate complete handler as passed to TimerQTerminate. This
  66. // is non-NULL only when our internal timer event handler must call it.
  67. //
  68. PTIMERQTERMINATECOMPLETE pHandler;
  69. // User's PTIMERQTERMINATECOMPLETE context passed back to 'pHandler'.
  70. //
  71. VOID* pContext;
  72. // Set when the timer queue is terminating. No other requests are
  73. // accepted when this is the case.
  74. //
  75. BOOLEAN fTerminating;
  76. // Spin lock protecting the 'listItems' list.
  77. //
  78. NDIS_SPIN_LOCK lock;
  79. // NDIS timer object.
  80. //
  81. NDIS_TIMER timer;
  82. }
  83. TIMERQ;
  84. // Timer queue event descriptor. All access should be via the TimerQ*
  85. // interface. There is no reason user should look inside. This is exposed to
  86. // allow user to efficiently manage allocation of TIMERQITEMS for several
  87. // timers from a large pool.
  88. //
  89. typedef struct
  90. _TIMERQITEM
  91. {
  92. // Links to the prev/next TIMERQITEM in the owning TIMERQ's chain of
  93. // pending timer events. Access is protected by 'lock' in the TIMERQ
  94. // structure.
  95. //
  96. LIST_ENTRY linkItems;
  97. // System time at which this event should occur.
  98. //
  99. LONGLONG llExpireTime;
  100. // User's routine to handle the timeout event when it occurs.
  101. //
  102. PTIMERQEVENT pHandler;
  103. // User's PTIMERQEVENT context passed back to 'pHandler'.
  104. //
  105. VOID* pContext;
  106. }
  107. TIMERQITEM;
  108. // Indicates the event which triggered user's callback to be called.
  109. //
  110. typedef enum
  111. _TIMERQEVENT
  112. {
  113. // The timeout interval has elapsed or user called TimerQExpireItem.
  114. //
  115. TE_Expire,
  116. // User called TimerQCancelItem.
  117. //
  118. TE_Cancel,
  119. // User called TimerQTerminateItem or called TimerQTerminate while the
  120. // item was queued.
  121. //
  122. TE_Terminate
  123. }
  124. TIMERQEVENT;
  125. //-----------------------------------------------------------------------------
  126. // Interface prototypes
  127. //-----------------------------------------------------------------------------
  128. BOOLEAN
  129. IsTimerQItemScheduled(
  130. IN TIMERQITEM* pItem );
  131. VOID
  132. TimerQInitialize(
  133. IN TIMERQ* pTimerQ );
  134. VOID
  135. TimerQInitializeItem(
  136. IN TIMERQITEM* pItem );
  137. VOID
  138. TimerQTerminate(
  139. IN TIMERQ* pTimerQ,
  140. IN PTIMERQTERMINATECOMPLETE pHandler,
  141. IN VOID* pContext );
  142. VOID
  143. TimerQScheduleItem(
  144. IN TIMERQ* pTimerQ,
  145. IN OUT TIMERQITEM* pNewItem,
  146. IN ULONG ulTimeoutMs,
  147. IN PTIMERQEVENT pHandler,
  148. IN VOID* pContext );
  149. BOOLEAN
  150. TimerQCancelItem(
  151. IN TIMERQ* pTimerQ,
  152. IN TIMERQITEM* pItem );
  153. BOOLEAN
  154. TimerQExpireItem(
  155. IN TIMERQ* pTimerQ,
  156. IN TIMERQITEM* pItem );
  157. CHAR*
  158. TimerQPszFromEvent(
  159. IN TIMERQEVENT event );
  160. BOOLEAN
  161. TimerQTerminateItem(
  162. IN TIMERQ* pTimerQ,
  163. IN TIMERQITEM* pItem );
  164. #endif // TIMER_H_