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.

120 lines
2.4 KiB

  1. //=================================================================
  2. //
  3. // TimerQueue.h
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include <windows.h>
  9. #include <deque>
  10. class CTimerEvent
  11. {
  12. public:
  13. CTimerEvent () : m_bEnabled ( FALSE ) , m_dwMilliseconds ( 1000 ) , m_bRepeating ( FALSE ) {} ;
  14. CTimerEvent ( DWORD dwTimeOut, BOOL fRepeat ) ;
  15. CTimerEvent ( const CTimerEvent &rTimerEvent ) ;
  16. virtual ~CTimerEvent () {} ;
  17. virtual void OnTimer () {} ;
  18. virtual ULONG AddRef () = 0 ;
  19. virtual ULONG Release () = 0 ;
  20. DWORD GetMilliSeconds () ;
  21. BOOL Repeating () ;
  22. BOOL Enabled () ;
  23. __int64 int64Time; // Scheduled callback as an offset of the system clock.
  24. protected:
  25. BOOL m_bEnabled ;
  26. DWORD m_dwMilliseconds; // Scheduled callback time in milliseconds
  27. BOOL m_bRepeating; // indicates a one shot or repeating callback
  28. void Disable () ;
  29. void Enable () ;
  30. };
  31. /*
  32. class CRuleTimerEvent : public CTimerEvent
  33. {
  34. protected:
  35. CRule *m_pRule ; // argument for the timed callback
  36. protected:
  37. CRuleTimerEvent ( CRule *a_Rule ) : m_Rule ( a_Rule ) { if ( m_Rule ) m_Rule->AddRef () } ;
  38. CRuleTimerEvent ( CRule *a_Rule , BOOL a_Enable , DWORD dwTimeOut, BOOL fRepeat ) ;
  39. CRuleTimerEvent ( const CRuleTimerEvent &rTimerEvent ) ;
  40. public:
  41. ~CRuleTimerEvent () {} ;
  42. CRule *GetRule () ;
  43. } ;
  44. */
  45. class CTimerQueue
  46. {
  47. public:
  48. static CTimerQueue s_TimerQueue ;
  49. public:
  50. CTimerQueue();
  51. ~CTimerQueue();
  52. void OnShutDown();
  53. void Init();
  54. BOOL QueueTimer( CTimerEvent *pTimerEntry );
  55. BOOL DeQueueTimer( CTimerEvent *pTimerEntry );
  56. protected:
  57. void vUpdateScheduler();
  58. __int64 int64Clock(); // System clock in milliseconds
  59. // pure virtual
  60. // virtual DWORD OnTimer( const CTimerEntry *pTimerEntry ) = 0;
  61. private:
  62. DWORD m_dwThreadID;
  63. HANDLE m_hSchedulerHandle;
  64. HANDLE m_hScheduleEvent;
  65. HANDLE m_hInitEvent;
  66. BOOL m_bInit;
  67. BOOL m_fShutDown;
  68. CStaticCritSec m_oCS;
  69. typedef std::deque<CTimerEvent*> Timer_Ptr_Queue;
  70. Timer_Ptr_Queue m_oTimerQueue;
  71. private:
  72. static DWORD WINAPI dwThreadProc( LPVOID lpParameter );
  73. BOOL fScheduleEvent( CTimerEvent* pTimerEvent );
  74. CTimerEvent* pGetNextTimerEvent();
  75. DWORD dwProcessSchedule();
  76. DWORD dwNextTimerEvent();
  77. void vEmptyList();
  78. BOOL ShutDown();
  79. };