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.

105 lines
4.0 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: timers.h
  6. *
  7. * Content: DirectPlay Thread Pool timer functions header file.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 10/31/01 VanceO Created.
  13. *
  14. ******************************************************************************/
  15. #ifndef __TIMERS_H__
  16. #define __TIMERS_H__
  17. //=============================================================================
  18. // Defines
  19. //=============================================================================
  20. #define DEFAULT_TIMER_BUCKET_GRANULARITY 4 // each timer bucket represents 4 ms of time, it must be a power of 2
  21. #define DEFAULT_NUM_TIMER_BUCKETS 1024 // store 1024 buckets (at 4 ms a pop, we track a total of 4096 ms of time)
  22. #ifdef DPNBUILD_DYNAMICTIMERSETTINGS
  23. #define TIMER_BUCKET_GRANULARITY(pWorkQueue) (pWorkQueue)->dwTimerBucketGranularity
  24. #define TIMER_BUCKET_GRANULARITY_CEILING(pWorkQueue) (pWorkQueue)->dwTimerBucketGranularityCeiling
  25. #define TIMER_BUCKET_GRANULARITY_FLOOR_MASK(pWorkQueue) (pWorkQueue)->dwTimerBucketGranularityFloorMask
  26. #define TIMER_BUCKET_GRANULARITY_DIVISOR(pWorkQueue) (pWorkQueue)->dwTimerBucketGranularityDivisor
  27. #define NUM_TIMER_BUCKETS(pWorkQueue) (pWorkQueue)->dwNumTimerBuckets
  28. #define NUM_TIMER_BUCKETS_MOD_MASK(pWorkQueue) (pWorkQueue)->dwNumTimerBucketsModMask
  29. #else // ! DPNBUILD_DYNAMICTIMERSETTINGS
  30. //
  31. // The granularity must be a power of 2 in order for our ceiling, mask and
  32. // divisor optimizations to work.
  33. //
  34. #define TIMER_BUCKET_GRANULARITY(pWorkQueue) DEFAULT_TIMER_BUCKET_GRANULARITY
  35. #if ((DEFAULT_TIMER_BUCKET_GRANULARITY - 1) & DEFAULT_TIMER_BUCKET_GRANULARITY)
  36. This Will Not Compile -- DEFAULT_TIMER_BUCKET_GRANULARITY must be a power of 2!
  37. #endif
  38. #define TIMER_BUCKET_GRANULARITY_CEILING(pWorkQueue) (DEFAULT_TIMER_BUCKET_GRANULARITY - 1)
  39. #define TIMER_BUCKET_GRANULARITY_FLOOR_MASK(pWorkQueue) (~(DEFAULT_TIMER_BUCKET_GRANULARITY - 1)) // negating the ceiling round factor (which happens to also be the modulo mask) gives us the floor mask
  40. #define TIMER_BUCKET_GRANULARITY_DIVISOR(pWorkQueue) (DEFAULT_TIMER_BUCKET_GRANULARITY >> 1)
  41. //
  42. // The bucket count must be a power of 2 in order for our mask optimizations to
  43. // work.
  44. //
  45. #define NUM_TIMER_BUCKETS(pWorkQueue) DEFAULT_NUM_TIMER_BUCKETS
  46. #if ((DEFAULT_NUM_TIMER_BUCKETS - 1) & DEFAULT_NUM_TIMER_BUCKETS)
  47. This Will Not Compile -- DEFAULT_NUM_TIMER_BUCKETS must be a power of 2!
  48. #endif
  49. #define NUM_TIMER_BUCKETS_MOD_MASK(pWorkQueue) (DEFAULT_NUM_TIMER_BUCKETS - 1)
  50. #endif // ! DPNBUILD_DYNAMICTIMERSETTINGS
  51. //=============================================================================
  52. // Function prototypes
  53. //=============================================================================
  54. HRESULT InitializeWorkQueueTimerInfo(DPTPWORKQUEUE * const pWorkQueue);
  55. void DeinitializeWorkQueueTimerInfo(DPTPWORKQUEUE * const pWorkQueue);
  56. BOOL ScheduleTimer(DPTPWORKQUEUE * const pWorkQueue,
  57. const DWORD dwDelay,
  58. const PFNDPTNWORKCALLBACK pfnWorkCallback,
  59. PVOID const pvCallbackContext,
  60. void ** const ppvTimerData,
  61. UINT * const puiTimerUnique);
  62. HRESULT CancelTimer(void * const pvTimerData,
  63. const UINT uiTimerUnique);
  64. void ResetCompletingTimer(void * const pvTimerData,
  65. const DWORD dwNewDelay,
  66. const PFNDPTNWORKCALLBACK pfnNewWorkCallback,
  67. PVOID const pvNewCallbackContext,
  68. UINT * const puiNewTimerUnique);
  69. #ifdef DPNBUILD_USEIOCOMPLETIONPORTS
  70. void ProcessTimers(DPTPWORKQUEUE * const pWorkQueue);
  71. #else // ! DPNBUILD_USEIOCOMPLETIONPORTS
  72. void ProcessTimers(DPTPWORKQUEUE * const pWorkQueue,
  73. DNSLIST_ENTRY ** const ppHead,
  74. DNSLIST_ENTRY ** const ppTail,
  75. USHORT * const pusCount);
  76. #endif // ! DPNBUILD_USEIOCOMPLETIONPORTS
  77. #endif // __TIMERS_H__