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.

294 lines
7.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: abktize.cxx
  7. //
  8. // Contents: Asynchronous Bucket->Window Conversion.
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 5-25-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <pch.cxx>
  18. #pragma hdrstop
  19. #include <bigtable.hxx>
  20. #include <execute.hxx>
  21. #include "tblbuket.hxx"
  22. #include "tabledbg.hxx"
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: CAsyncBucketExploder ~ctor
  26. //
  27. // Arguments: [largeTable] -- LargeTable driving the bucket->window
  28. // conversion.
  29. // [pBucket] -- The bucket to expand into a window.
  30. // [widToPin] -- WORKID to pin.
  31. // [fDoWidToPath] -- TRUE if table holds 'fake' wids, and bucket
  32. // must convert fake wid to path.
  33. //
  34. // History: 5-25-95 srikants Created
  35. //
  36. // Notes:
  37. //
  38. //----------------------------------------------------------------------------
  39. CAsyncBucketExploder::CAsyncBucketExploder( CLargeTable & largeTable,
  40. XPtr<CTableBucket> & xBucket,
  41. WORKID widToPin,
  42. BOOL fDoWidToPath )
  43. : PWorkItem(eSigCAsyncBucketExploder),
  44. _largeTable(largeTable),
  45. _pBucket(0),
  46. _widToPin(widToPin),
  47. _fDoWidToPath( fDoWidToPath ),
  48. _pQueryExecute(0),
  49. _refCount(1),
  50. _fOnWorkQueue(FALSE),
  51. _fOnLTList(FALSE),
  52. _status(STATUS_SUCCESS)
  53. {
  54. Close(); // Initialize the links to point to self.
  55. _pBucket = xBucket.Acquire();
  56. Win4Assert( 0 != _pBucket );
  57. END_CONSTRUCTION( CAsyncBucketExploder );
  58. }
  59. //+---------------------------------------------------------------------------
  60. //
  61. // Function: CAsyncBucketExploder
  62. //
  63. // Synopsis: ~dtor
  64. //
  65. // History: 5-25-95 srikants Created
  66. //
  67. // Notes:
  68. //
  69. //----------------------------------------------------------------------------
  70. CAsyncBucketExploder::~CAsyncBucketExploder()
  71. {
  72. Win4Assert( 0 == _refCount );
  73. Win4Assert( IsSingle() ); // Is not linked in the list
  74. Win4Assert( !_fOnWorkQueue );
  75. Win4Assert( !_fOnLTList );
  76. if ( 0 != _pQueryExecute )
  77. {
  78. _pQueryExecute->Release();
  79. }
  80. delete _pBucket;
  81. }
  82. //+---------------------------------------------------------------------------
  83. //
  84. // Function: DoIt
  85. //
  86. // Synopsis: The main method called by the worker thread .
  87. //
  88. // Arguments: [pThread] -- Thread executing request.
  89. //
  90. // History: 5-25-95 srikants Created
  91. //
  92. // Notes: At the end, if this object in the LargeTable's list, it will
  93. // be removed from the large table list. While doing that,
  94. // DO NOT hold the mutex because there LT can call into this
  95. // object with its lock held. We don't want to deadlock.
  96. //
  97. //----------------------------------------------------------------------------
  98. void CAsyncBucketExploder::DoIt( CWorkThread * pThread )
  99. {
  100. {
  101. CLock lock(_mutex);
  102. Win4Assert( 0 != _pBucket );
  103. Win4Assert( 0 != _pQueryExecute );
  104. _fOnWorkQueue = FALSE;
  105. }
  106. AddRef();
  107. //
  108. // None of these calls throw
  109. //
  110. CBucketRowIter bktIter( *_pBucket, _fDoWidToPath );
  111. _pQueryExecute->Update( bktIter );
  112. //
  113. // If it is on the large table queue, remove it from the lt queue.
  114. //
  115. if ( _fOnLTList )
  116. {
  117. _fOnLTList = FALSE;
  118. _largeTable._RemoveFromExplodeList(this);
  119. }
  120. _evt.Set();
  121. Release();
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Function: SetQuery
  126. //
  127. // Synopsis: Sets the query object to be used for bucket->window conversion.
  128. //
  129. // Arguments: [pQExecute] - The Query object to use for bucket->window
  130. // conversion.
  131. //
  132. // History: 5-25-95 srikants Created
  133. //
  134. // Notes:
  135. //
  136. //----------------------------------------------------------------------------
  137. void CAsyncBucketExploder::SetQuery( CQAsyncExecute * pQExecute )
  138. {
  139. CLock lock(_mutex);
  140. Win4Assert( 0 == _pQueryExecute && 0 != pQExecute );
  141. _pQueryExecute = pQExecute;
  142. _pQueryExecute->AddRef();
  143. }
  144. //+---------------------------------------------------------------------------
  145. //
  146. // Function: SetOnLTList
  147. //
  148. // Synopsis: Sets the internal state that it is on the large table's
  149. // list also.
  150. //
  151. // History: 5-31-95 srikants Created
  152. //
  153. // Notes:
  154. //
  155. //----------------------------------------------------------------------------
  156. void CAsyncBucketExploder::SetOnLTList()
  157. {
  158. CLock lock(_mutex);
  159. Win4Assert( !_fOnLTList );
  160. _fOnLTList = TRUE;
  161. }
  162. //+---------------------------------------------------------------------------
  163. //
  164. // Function: AddToWorkQueue
  165. //
  166. // Synopsis: Adds this item to the work queue.
  167. //
  168. // History: 5-31-95 srikants Created
  169. //
  170. // Notes:
  171. //
  172. //----------------------------------------------------------------------------
  173. void CAsyncBucketExploder::AddToWorkQueue()
  174. {
  175. CLock lock(_mutex);
  176. Win4Assert( !_fOnWorkQueue );
  177. _fOnWorkQueue = TRUE;
  178. TheWorkQueue.Add(this);
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // Function: Abort
  183. //
  184. // Synopsis: Aborts the work item by removing it from the work queue
  185. // (if present). It also releases the query object.
  186. //
  187. // History: 5-31-95 srikants Created
  188. //
  189. // Notes:
  190. //
  191. //----------------------------------------------------------------------------
  192. void CAsyncBucketExploder::Abort()
  193. {
  194. CLock lock(_mutex);
  195. Win4Assert( IsSingle() ); // Must not be on any list at this stage
  196. _fOnLTList = FALSE;
  197. if ( _fOnWorkQueue )
  198. {
  199. TheWorkQueue.Remove(this);
  200. _fOnWorkQueue = FALSE;
  201. }
  202. if ( 0 != _pQueryExecute )
  203. {
  204. _pQueryExecute->Release();
  205. _pQueryExecute = 0;
  206. }
  207. _evt.Set(); // Wake up any thread waiting on us
  208. }
  209. //+---------------------------------------------------------------------------
  210. //
  211. // Function: AddRef
  212. //
  213. // Synopsis:
  214. //
  215. // Returns:
  216. //
  217. // Modifies:
  218. //
  219. // History: 5-31-95 srikants Created
  220. //
  221. // Notes:
  222. //
  223. //----------------------------------------------------------------------------
  224. void CAsyncBucketExploder::AddRef()
  225. {
  226. InterlockedIncrement(&_refCount);
  227. }
  228. //+---------------------------------------------------------------------------
  229. //
  230. // Function: Release
  231. //
  232. // Synopsis:
  233. //
  234. // Returns:
  235. //
  236. // Modifies:
  237. //
  238. // History: 5-31-95 srikants Created
  239. //
  240. // Notes:
  241. //
  242. //----------------------------------------------------------------------------
  243. void CAsyncBucketExploder::Release()
  244. {
  245. Win4Assert( _refCount > 0 );
  246. if ( InterlockedDecrement(&_refCount) <= 0 )
  247. {
  248. delete this;
  249. }
  250. }