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.

158 lines
3.6 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: idle.h
  7. *
  8. * Contents: Interface file for CIdleTaskQueue
  9. *
  10. * History: 13-Apr-99 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef IDLE_H
  14. #define IDLE_H
  15. #pragma once
  16. #include <queue>
  17. typedef enum tagIdleTaskPriority
  18. {
  19. ePriority_Low,
  20. ePriority_Normal,
  21. ePriority_High
  22. } IdleTaskPriority;
  23. class CIdleTask
  24. {
  25. public:
  26. CIdleTask();
  27. virtual ~CIdleTask();
  28. CIdleTask(const CIdleTask &rhs);
  29. CIdleTask& operator= (const CIdleTask& rhs);
  30. virtual SC ScDoWork() = 0;
  31. virtual SC ScGetTaskID(ATOM* pID) = 0;
  32. /*
  33. * Merge from pitMergeFrom into the called idle task.
  34. *
  35. * S_OK the tasks have been merged and pitMergeFrom can be discarded
  36. *
  37. * S_FALSE these two tasks cannot be merged and you wish the idle task
  38. * manager to continue searching for idle tasks into which
  39. * pitMergeFrom can be merged.
  40. *
  41. * E_FAIL these two tasks cannot be merged and you do not wish the idle
  42. * task manager to continue searching for idle tasks into which
  43. * pitMergeFrom can be merged.
  44. */
  45. virtual SC ScMerge(CIdleTask* pitMergeFrom) = 0;
  46. };
  47. class CIdleQueueEntry
  48. {
  49. public:
  50. CIdleQueueEntry () :
  51. m_ePriority (ePriority_Normal)
  52. {
  53. DEBUG_INCREMENT_INSTANCE_COUNTER(CIdleQueueEntry);
  54. }
  55. CIdleQueueEntry (CIdleTask *pIdleTask, IdleTaskPriority ePriority = ePriority_Normal) :
  56. m_pTask(pIdleTask), m_ePriority (ePriority)
  57. {
  58. DEBUG_INCREMENT_INSTANCE_COUNTER(CIdleQueueEntry);
  59. }
  60. ~CIdleQueueEntry()
  61. {
  62. DEBUG_DECREMENT_INSTANCE_COUNTER(CIdleQueueEntry);
  63. }
  64. CIdleQueueEntry(const CIdleQueueEntry &rhs);
  65. CIdleQueueEntry& operator= (const CIdleQueueEntry& rhs);
  66. bool operator< (const CIdleQueueEntry& other) const
  67. {
  68. return (m_ePriority < other.m_ePriority);
  69. }
  70. private:
  71. CIdleTask * m_pTask;
  72. IdleTaskPriority m_ePriority;
  73. public:
  74. CIdleTask * GetTask() const {return m_pTask;}
  75. IdleTaskPriority GetPriority () const {return m_ePriority;}
  76. };
  77. /*
  78. * Determines if a CIdleQueueEntry matches a given task ID.
  79. */
  80. struct EqualTaskID : std::binary_function<CIdleQueueEntry, ATOM, bool>
  81. {
  82. bool operator()(const CIdleQueueEntry& iqe, ATOM idToMatch) const
  83. {
  84. ATOM id;
  85. SC sc = iqe.GetTask()->ScGetTaskID(&id);
  86. if(sc)
  87. return (false);
  88. return (id == idToMatch);
  89. }
  90. };
  91. /*
  92. * accessible_priority_queue - thin wrapper around std::prority_queue to
  93. * provide access to the container iterators
  94. */
  95. template<class _Ty, class _C = std::vector<_Ty>, class _Pr = std::less<_C::value_type> >
  96. class accessible_priority_queue : public std::priority_queue<_Ty, _C, _Pr>
  97. {
  98. public:
  99. typedef _C::iterator iterator;
  100. iterator begin()
  101. { return (c.begin()); }
  102. iterator end()
  103. { return (c.end()); }
  104. };
  105. class CIdleTaskQueue
  106. {
  107. public:
  108. CIdleTaskQueue();
  109. ~CIdleTaskQueue();
  110. // CIdleTaskManager methods
  111. SC ScPushTask (CIdleTask* pitToPush, IdleTaskPriority ePriority);
  112. SC ScPerformNextTask();
  113. SC ScGetTaskCount (LONG_PTR* plCount);
  114. private:
  115. typedef accessible_priority_queue<CIdleQueueEntry> Queue;
  116. Queue::iterator FindTaskByID (
  117. Queue::iterator itFirst,
  118. Queue::iterator itLast,
  119. ATOM idToFind);
  120. private:
  121. Queue m_queue;
  122. };
  123. #endif /* IDLE_H */