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.

113 lines
3.2 KiB

  1. /*=========================================================================*\
  2. Module: idlethrd.h
  3. Copyright Microsoft Corporation 1997, All Rights Reserved.
  4. Author: zyang
  5. Description: Idle thread implementation
  6. \*=========================================================================*/
  7. #ifndef _EX_IDLETHRD_H_
  8. #define _EX_IDLETHRD_H_
  9. #include <ex\refcnt.h>
  10. // Interface IIdleThreadCallBack
  11. //
  12. // This is a pure virtual class. which is to be implemented by any caller
  13. // who wants to register a callback on the idle thread. It has two methods.
  14. //
  15. // DwWait(): return the next time out value. this allows the client to
  16. // change the timeout value dynamically. This method is also called when the
  17. // callback is register obtain the initial timeout value, in this case, zero
  18. // means execute immediately.
  19. //
  20. // FExecute(): called when the time out happens, client should return
  21. // TRUE if client want to keep this registration
  22. // FALSE if the client wants to unregister
  23. //
  24. // IMPORTANT:
  25. // As there could be huge numder of registration on the idle thread, client
  26. // should not block the Execute(), otherwise, other registrations would be
  27. // blocked.
  28. //
  29. class IIdleThreadCallBack : private CRefCountedObject,
  30. public IRefCounted
  31. {
  32. ULONG m_ulIndex; // This is to facilitate unregister
  33. // should not be touched by the client
  34. // non-implemented
  35. //
  36. IIdleThreadCallBack( const IIdleThreadCallBack& );
  37. IIdleThreadCallBack& operator=( const IIdleThreadCallBack& );
  38. protected:
  39. IIdleThreadCallBack() {};
  40. public:
  41. // Client should not touch these two methods
  42. //
  43. VOID SetIndex (ULONG ulIndex) { m_ulIndex = ulIndex; }
  44. const ULONG UlIndex () { return m_ulIndex; }
  45. // Client should implement the following methods
  46. // Return the next timeout, in milliseconds.
  47. //
  48. virtual DWORD DwWait() = 0;
  49. // Called when timed out
  50. //
  51. virtual BOOL FExecute() = 0;
  52. // Tell the clients that the idle thread is being shutdown
  53. //
  54. virtual VOID Shutdown() = 0;
  55. // RefCounting -- forward all reconting requests to our refcounting
  56. // implementation base class: CRefCountedObject
  57. //
  58. void AddRef() { CRefCountedObject::AddRef(); }
  59. void Release() { CRefCountedObject::Release(); }
  60. };
  61. // Helper functions
  62. // FInitIdleThread
  63. //
  64. // Initialize the idle thread object. It can be out only once,
  65. // Note this call only initialize the CIdleThread object, the
  66. // idle thread is not started until the first registration
  67. //
  68. BOOL FInitIdleThread();
  69. // FDeleteIdleThread
  70. //
  71. // Delete the idle thread object. again, it can be called only once.
  72. //
  73. // Note this must be called before any other uninitialization work,
  74. // Because we don't own a ref to the callback object, all what we
  75. // have is a pointer to the object. in the shutdown time, we must
  76. // clear all the callback registration before the callback object
  77. // go away.
  78. //
  79. VOID DeleteIdleThread();
  80. // FRegister
  81. //
  82. // Register a callback
  83. //
  84. BOOL FRegister (IIdleThreadCallBack * pCallBack);
  85. // Unregister
  86. //
  87. // Unregister a callback
  88. //
  89. VOID Unregister (IIdleThreadCallBack * pCallBack);
  90. #endif // !_EX_IDLETHRD_H_