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.

267 lines
6.3 KiB

  1. //=============================================================================
  2. // Copyright (c) 1997 Microsoft Corporation
  3. //
  4. // File Name: igmptimer.h
  5. //
  6. // Abstract:
  7. // This module contains declarations related to igmptimer.
  8. //
  9. // Author: K.S.Lokesh (lokeshs@) 11-1-97
  10. //
  11. // Revision History:
  12. //
  13. //=============================================================================
  14. #ifndef _IGMP_TIMER_H_
  15. #define _IGMP_TIMER_H_
  16. VOID
  17. DebugCheckTimerContexts(
  18. );
  19. //
  20. // set the debug timer flags, so that I can control the amount of tracing
  21. // printed out.
  22. //
  23. #if DBG
  24. #ifndef DEBUG_TIMER_LEVEL
  25. #define DEBUG_TIMER_LEVEL 0x0
  26. #endif
  27. #else
  28. #ifdef DEBUG_TIMER_LEVEL
  29. #undef DEBUG_TIMER_LEVEL
  30. #endif
  31. #define DEBUG_TIMER_LEVEL 0x0
  32. #endif
  33. #define DBG_Y TRUE
  34. #define DBG_N FALSE
  35. #define DEBUG_TIMER_ACTIVITY (DEBUG_TIMER_LEVEL & 0x00000001)
  36. #define DEBUG_TIMER_TIMERID (DEBUG_TIMER_LEVEL & 0x00000010)
  37. #define DEBUG_FLAGS_SIGNATURE (DEBUG_TIMER_LEVEL & 0x00000010)
  38. #define DEBUG_TIMER_PROCESSQUEUE1 (DEBUG_TIMER_LEVEL & 0x00000020)
  39. #define DEBUG_TIMER_PROCESSQUEUE2 (DEBUG_TIMER_LEVEL & 0x00000040)
  40. #define DEBUG_TIMER_RESYNCTIMER (DEBUG_TIMER_LEVEL & 0x00000080)
  41. #define DEBUG_TIMER_REMOVETIMER1 (DEBUG_TIMER_LEVEL & 0x00000100)
  42. #define DEBUG_TIMER_REMOVETIMER2 (DEBUG_TIMER_LEVEL & 0x00000200)
  43. #define DEBUG_TIMER_INSERTTIMER1 (DEBUG_TIMER_LEVEL & 0x00001000)
  44. #define DEBUG_TIMER_INSERTTIMER2 (DEBUG_TIMER_LEVEL & 0x00002000)
  45. #define DEBUG_TIMER_UPDATETIMER1 (DEBUG_TIMER_LEVEL & 0x00010000)
  46. #define DEBUG_TIMER_PACKET (DEBUG_TIMER_LEVEL & 0x00020000)
  47. //------------------------------------------------------------------------------
  48. // GLOBAL DEFINITIONS
  49. //
  50. // number of buckets in Timer Table
  51. // 0-14,14-28,28-42,... last bucket has >63*14=882 secs (all approx)
  52. //
  53. #define NUM_TIMER_BUCKETS 64
  54. #if DEBUG_TIMER_TIMERID
  55. extern DWORD TimerId;
  56. #endif
  57. typedef struct _IGMP_TIMER_ENTRY {
  58. LIST_ENTRY Link;
  59. LONGLONG Timeout;
  60. LPTHREAD_START_ROUTINE Function;
  61. PVOID Context;
  62. UCHAR Status;
  63. #if DEBUG_TIMER_TIMERID
  64. DWORD Id;
  65. DWORD Id2;
  66. DWORD IfIndex;
  67. DWORD Group;
  68. DWORD Source;
  69. DWORD Signature; //0xfadfad01
  70. #endif
  71. } IGMP_TIMER_ENTRY, *PIGMP_TIMER_ENTRY;
  72. #if DEBUG_FLAGS_SIGNATURE && DEBUG_TIMER_TIMERID
  73. #define CHECK_TIMER_SIGNATURE(pte) {\
  74. if ((pte)->Signature != 0xfadfad01)\
  75. DbgBreakPoint();\
  76. }
  77. #else
  78. #define CHECK_TIMER_SIGNATURE(pte)
  79. #endif
  80. typedef struct _IGMP_TIMER_GLOBAL {
  81. HANDLE WTTimer; // timer set with wait server
  82. HANDLE WTTimer1;
  83. LONGLONG WTTimeout; // timeout value set with wait server
  84. LONGLONG SyncTime; // time when time queue last reordered
  85. LARGE_INTEGER CurrentTime;
  86. DWORD NumTimers;
  87. DWORD TableLowIndex;
  88. LIST_ENTRY TimesTable[NUM_TIMER_BUCKETS]; // array of times
  89. UCHAR Status;
  90. CRITICAL_SECTION CS;
  91. BOOL CSFlag;
  92. } IGMP_TIMER_GLOBAL, *PIGMP_TIMER_GLOBAL;
  93. #define GET_IGMP_CURRENT_TIME( ) igmp.WTTimer.CurrentTime.QuadPart
  94. // TIMER_STATUS
  95. #define TIMER_STATUS_CREATED 0x01
  96. #define TIMER_STATUS_INACTIVE 0x02
  97. #define TIMER_STATUS_ACTIVE 0x04
  98. #define TIMER_STATUS_FIRED 0x08
  99. #define TIMER_STATUS_DELETED 0x80
  100. //
  101. // MACROS
  102. //
  103. #define IS_TIMER_ACTIVE(pTimer) ((pTimer).Status & TIMER_STATUS_ACTIVE)
  104. #define SET_TIMER_INFINITE(time) \
  105. time = 0
  106. #define IS_TIMER_INFINITE(time) \
  107. (time == 0)
  108. #if DEBUG_FLAGS_SIGNATURE //deldel
  109. #define ACQUIRE_TIMER_LOCK(proc) { \
  110. ENTER_CRITICAL_SECTION(&g_TimerStruct.CS, "g_TimerStruct.CS1", proc); \
  111. ++g_TimerStruct.CSFlag; \
  112. }
  113. #define RELEASE_TIMER_LOCK(proc) {\
  114. --g_TimerStruct.CSFlag; \
  115. LEAVE_CRITICAL_SECTION(&g_TimerStruct.CS, "g_TimerStruct.CS1", proc); \
  116. }
  117. #define CHECK_IF_ACQUIRED_TIMER_LOCK() {\
  118. if (g_TimerStruct.CSFlag<=0) DbgBreakPoint();\
  119. }
  120. #else
  121. #define ACQUIRE_TIMER_LOCK(proc) { \
  122. ENTER_CRITICAL_SECTION(&g_TimerStruct.CS, "g_TimerStruct.CS1", proc); \
  123. }
  124. #define RELEASE_TIMER_LOCK(proc) {\
  125. LEAVE_CRITICAL_SECTION(&g_TimerStruct.CS, "g_TimerStruct.CS1", proc); \
  126. }
  127. #define CHECK_IF_ACQUIRED_TIMER_LOCK()
  128. #endif
  129. #define SET_TIMER_ID(_pTimer, _Id1, _IfIndex, _Group, _Source) {\
  130. (_pTimer)->Id = _Id1; \
  131. (_pTimer)->Id2 = TimerId++;\
  132. (_pTimer)->IfIndex = _IfIndex;\
  133. (_pTimer)->Group = _Group; \
  134. (_pTimer)->Source = _Source; \
  135. (_pTimer)->Signature = 0xfadfad01; \
  136. }
  137. //
  138. // currently all times mentioned in the config structure are in seconds
  139. //
  140. #define CONV_CONFIG_TO_INTERNAL_TIME(time) \
  141. (time *= 1000)
  142. #define CONFIG_TO_INTERNAL_TIME(time) \
  143. ((time) * 1000)
  144. #define CONV_INTERNAL_TO_CONFIG_TIME(time) \
  145. (time /= 1000);
  146. #define CONFIG_TO_SYSTEM_TIME(time) \
  147. (time)
  148. #define SYSTEM_TIME_TO_SEC(time) \
  149. ((DWORD)((time) / (LONGLONG)1000L))
  150. #define SYSTEM_TIME_TO_MSEC(time) \
  151. ((DWORD)(time))
  152. //
  153. //FUNCTION PROTOTYPES
  154. //
  155. LONGLONG
  156. GetCurrentIgmpTime(
  157. );
  158. VOID
  159. UpdateLocalTimer (
  160. PIGMP_TIMER_ENTRY pte,
  161. LONGLONG llNewTime,
  162. BOOL bDbgPrint
  163. );
  164. VOID
  165. RemoveTimer (
  166. PIGMP_TIMER_ENTRY pte,
  167. BOOL bDbg
  168. );
  169. DWORD
  170. InsertTimer (
  171. PIGMP_TIMER_ENTRY pte,
  172. LONGLONG llNewTime,
  173. BOOL bResync,
  174. BOOL bDbg
  175. );
  176. ULONG
  177. QueryRemainingTime(
  178. PIGMP_TIMER_ENTRY pte,
  179. LONGLONG llCurTime
  180. );
  181. DWORD
  182. InitializeTimerGlobal (
  183. );
  184. VOID
  185. DeInitializeTimerGlobal (
  186. );
  187. VOID
  188. DebugPrintTimerEntry (
  189. PIGMP_TIMER_ENTRY pte,
  190. DWORD dwBucket,
  191. LONGLONG llCurTime
  192. );
  193. VOID
  194. GetTimerDebugInfo(
  195. CHAR str1[20],
  196. CHAR str2[20],
  197. DWORD *pdwDiffTime,
  198. PIGMP_TIMER_ENTRY pte,
  199. LONGLONG llCurtime
  200. );
  201. DWORD
  202. DebugScanTimerQueue(
  203. DWORD Id
  204. );
  205. VOID
  206. DebugPrintTimerQueue (
  207. );
  208. #endif //ifndef _IGMP_TIMER_H_