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.

266 lines
6.0 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // TaskAnalyzeCluster.cpp
  7. //
  8. // Description:
  9. // CTaskTracking implementation
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 16-AUG-2001
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "TaskTracking.h"
  17. //////////////////////////////////////////////////////////////////////////////
  18. //++
  19. //
  20. // CTaskTracking::CTaskTracking
  21. //
  22. // Description:
  23. // Constructor
  24. //
  25. // Arguments:
  26. // None.
  27. //
  28. // Return Value:
  29. // None.
  30. //
  31. //--
  32. //////////////////////////////////////////////////////////////////////////////
  33. CTaskTracking::CTaskTracking( void )
  34. {
  35. TraceFunc( "" );
  36. InterlockedIncrement( &g_cObjects );
  37. Assert( m_prgTasks == NULL );
  38. Assert( m_idxTaskNext == 0 );
  39. TraceFuncExit();
  40. } //*** CTaskTracking::CTaskTracking
  41. //////////////////////////////////////////////////////////////////////////////
  42. //++
  43. //
  44. // CTaskTracking::~CTaskTracking
  45. //
  46. // Description:
  47. // Destructor
  48. //
  49. // Arguments:
  50. // None.
  51. //
  52. // Return Value:
  53. // None.
  54. //
  55. //--
  56. //////////////////////////////////////////////////////////////////////////////
  57. CTaskTracking::~CTaskTracking( void )
  58. {
  59. TraceFunc( "" );
  60. ULONG idx;
  61. Assert( m_idxTaskNext == 0 );
  62. for ( idx = 0; idx < m_idxTaskNext; idx++ )
  63. {
  64. THR( (m_prgTasks[ idx ].pidt)->Release() );
  65. } // for:
  66. TraceFree( m_prgTasks );
  67. InterlockedDecrement( &g_cObjects );
  68. TraceFuncExit();
  69. } //*** CTaskTracking::~CTaskTracking
  70. //////////////////////////////////////////////////////////////////////////////
  71. //++
  72. //
  73. // CTaskTracking::HrAddTaskToTrackingList
  74. //
  75. // Description:
  76. // Add the passed in task to the side list of tasks that may need
  77. // to be cancelled.
  78. //
  79. // Arguments:
  80. // punkIn
  81. // The task object to add to the list.
  82. //
  83. // cookieIn
  84. // Completion cookie for the task. Will be used to remove the
  85. // task from the list when a task completes.
  86. //
  87. // Return Value:
  88. // S_OK
  89. // Success.
  90. //
  91. // Other HRESULT error.
  92. //
  93. //--
  94. //////////////////////////////////////////////////////////////////////////////
  95. HRESULT
  96. CTaskTracking::HrAddTaskToTrackingList(
  97. IUnknown * punkIn
  98. , OBJECTCOOKIE cookieIn
  99. )
  100. {
  101. TraceFunc( "" );
  102. Assert( punkIn != NULL );
  103. HRESULT hr = S_OK;
  104. TaskTrackingEntry * prgTemp = NULL;
  105. IDoTask * pidt = NULL;
  106. prgTemp = (TaskTrackingEntry *) TraceReAlloc(
  107. m_prgTasks
  108. , sizeof( TaskTrackingEntry ) * ( m_idxTaskNext + 1 )
  109. , HEAP_ZERO_MEMORY
  110. );
  111. if ( prgTemp == NULL )
  112. {
  113. hr = THR( E_OUTOFMEMORY );
  114. goto Cleanup;
  115. } // if:
  116. m_prgTasks = prgTemp;
  117. hr = THR( punkIn->TypeSafeQI( IDoTask, &pidt ) );
  118. if ( FAILED( hr ) )
  119. {
  120. goto Cleanup;
  121. } // if:
  122. m_prgTasks[ m_idxTaskNext ].pidt = pidt;
  123. m_prgTasks[ m_idxTaskNext++ ].ocCompletion = cookieIn;
  124. Cleanup:
  125. HRETURN( hr );
  126. } //*** CTaskTracking::HrAddTaskToTrackingList
  127. //////////////////////////////////////////////////////////////////////////////
  128. //++
  129. //
  130. // CTaskTracking::HrRemoveTaskFromTrackingList
  131. //
  132. // Description:
  133. // Remove the task which has the passed in cookie associated with it.
  134. //
  135. // Arguments:
  136. // cookieIn
  137. // Completion cookie for the task. Will be used to remove the
  138. // task from the list when a task completes.
  139. //
  140. // Return Value:
  141. // S_OK
  142. // Success.
  143. //
  144. // Other HRESULT error.
  145. //
  146. //--
  147. //////////////////////////////////////////////////////////////////////////////
  148. HRESULT
  149. CTaskTracking::HrRemoveTaskFromTrackingList(
  150. OBJECTCOOKIE cookieIn
  151. )
  152. {
  153. TraceFunc( "" );
  154. Assert( m_idxTaskNext != NULL );
  155. HRESULT hr = S_OK;
  156. ULONG idxOuter;
  157. ULONG idxInner;
  158. //
  159. // Find the entry that contains the passed in cookie.
  160. //
  161. for ( idxOuter = 0; idxOuter < m_idxTaskNext; idxOuter++ )
  162. {
  163. if ( m_prgTasks[ idxOuter ].ocCompletion == cookieIn )
  164. {
  165. //
  166. // Release out ref on the task object.
  167. //
  168. (m_prgTasks[ idxOuter ].pidt)->Release();
  169. //
  170. // Shift the remaining entries to the left. Need to stop one before the end
  171. // because there is no need to move the end plus one...
  172. //
  173. for ( idxInner = idxOuter; idxInner < m_idxTaskNext - 1; idxInner++ )
  174. {
  175. m_prgTasks[ idxInner ] = m_prgTasks[ idxInner + 1 ];
  176. } // for:
  177. //
  178. // Decrement the count/next index
  179. //
  180. m_idxTaskNext -= 1;
  181. break;
  182. } // if:
  183. } // for:
  184. HRETURN( hr );
  185. } //*** CTaskTracking::HrRemoveTaskFromTrackingList
  186. //////////////////////////////////////////////////////////////////////////////
  187. //++
  188. //
  189. // CTaskTracking::HrNotifyAllTasksToStop
  190. //
  191. // Description:
  192. // Notify all tasks in the tracking list that the need to stop.
  193. //
  194. // Arguments:
  195. // None.
  196. //
  197. // Return Value:
  198. // S_OK
  199. // Success.
  200. //
  201. // Other HRESULT error.
  202. //
  203. //--
  204. //////////////////////////////////////////////////////////////////////////////
  205. HRESULT
  206. CTaskTracking::HrNotifyAllTasksToStop(
  207. void
  208. )
  209. {
  210. TraceFunc( "" );
  211. HRESULT hr = S_OK;
  212. ULONG idx;
  213. //
  214. // Enum each task and tell it to stop.
  215. //
  216. for ( idx = 0; idx < m_idxTaskNext; idx++ )
  217. {
  218. THR( (m_prgTasks[ idx ].pidt)->StopTask() );
  219. } // for:
  220. HRETURN( hr );
  221. } //*** CTaskTracking::HrNotifyAllTasksToStop