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.

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