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.

282 lines
7.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000
  5. //
  6. // File: RowMan.cxx
  7. //
  8. // Contents: Distributed HROW manager.
  9. //
  10. // Classes: CHRowManager
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. // 14-JAN-97 KrishnaN Undefined CI_INETSRV and related changes
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include "rowman.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CHRowManager::CHRowManager, public
  22. //
  23. // Synopsis: Initializes row manager.
  24. //
  25. // History: 05-Jun-95 KyleP Created.
  26. //
  27. //----------------------------------------------------------------------------
  28. CHRowManager::CHRowManager()
  29. : _aHRow( 0 ),
  30. _cHRow( 50 ),
  31. _iFirstFree( 0 ),
  32. _cChild( 0 ),
  33. _ahrowHint( 0 )
  34. {
  35. _aHRow = new CHRow [_cHRow];
  36. for ( unsigned i = 0; i < _cHRow-1; i++ )
  37. {
  38. _aHRow[i].Link( i + 1 );
  39. }
  40. _aHRow[_cHRow-1].Link( -1 );
  41. }
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Member: CHRowManager::~CHRowManager, public
  45. //
  46. // Synopsis: Destructor
  47. //
  48. // History: 05-Jun-95 KyleP Created.
  49. //
  50. //----------------------------------------------------------------------------
  51. CHRowManager::~CHRowManager()
  52. {
  53. #if CIDBG == 1
  54. for ( unsigned i = 0; i < _cHRow; i++ )
  55. {
  56. if ( _aHRow[i].IsInUse() )
  57. vqDebugOut(( DEB_WARN, "CHRowManager: HROW %d still in use\n", i ));
  58. Win4Assert( !_aHRow[i].IsInUse() );
  59. }
  60. #endif
  61. delete [] _aHRow;
  62. delete [] _ahrowHint;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // Member: CHRowManager::TrackSiblings, public
  67. //
  68. // Synopsis: Turns on tracking of siblings.
  69. //
  70. // Arguments: [cChild] -- Number of child cursors.
  71. //
  72. // History: 05-Jun-95 KyleP Created.
  73. //
  74. //----------------------------------------------------------------------------
  75. void CHRowManager::TrackSiblings( unsigned cChild )
  76. {
  77. _cChild = cChild;
  78. _ahrowHint = new HROW [_cHRow * _cChild];
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Member: CHRowManager::Add, public
  83. //
  84. // Synopsis: Adds a new HROW to be tracked.
  85. //
  86. // Arguments: [iChild] -- Index of governing child cursor.
  87. // [hrow] -- HROW used by child cursor
  88. //
  89. // Returns: HROW used by distributed row manager.
  90. //
  91. // History: 05-Jun-95 KyleP Created.
  92. //
  93. //----------------------------------------------------------------------------
  94. HROW CHRowManager::Add( unsigned iChild, HROW hrow )
  95. {
  96. int iCurrent = InnerAdd( iChild, hrow );
  97. vqDebugOut(( DEB_ITRACE, "CHRowManager::Add HROW distr=%d child=%d,%d\n",
  98. iCurrent, iChild, hrow));
  99. if ( IsTrackingSiblings() )
  100. {
  101. RtlFillMemory( _ahrowHint + (iCurrent * _cChild),
  102. _cChild * sizeof(HROW),
  103. 0xFF );
  104. _ahrowHint[iCurrent*_cChild + iChild] = hrow;
  105. }
  106. return (HROW)( iCurrent+1 ); // we are 0 based while hrow is 1 based
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Member: CHRowManager::Add, public
  111. //
  112. // Synopsis: Adds a new HROW to be tracked, including hints.
  113. //
  114. // Arguments: [iChild] -- Index of governing child cursor.
  115. // [ahrow] -- Array of HROW, one per child cursor.
  116. //
  117. // Returns: HROW used by distributed row manager.
  118. //
  119. // History: 05-Jun-95 KyleP Created.
  120. //
  121. //----------------------------------------------------------------------------
  122. HROW CHRowManager::Add( unsigned iChild, HROW const * ahrow )
  123. {
  124. int iCurrent = InnerAdd( iChild, ahrow[iChild] );
  125. vqDebugOut(( DEB_ITRACE, "CHRowManager::Add HROW distr=%d child=%d,%d\n",
  126. iCurrent, iChild, ahrow[iChild] ));
  127. RtlCopyMemory( _ahrowHint + (iCurrent * _cChild),
  128. ahrow,
  129. _cChild * sizeof(HROW) );
  130. return (HROW)( iCurrent+1 ); // we are 0 based while hrow is 1 based
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Member: CHRowManager::AddRef, public
  135. //
  136. // Synopsis: De-refs a given hrow
  137. //
  138. // Arguments: [hrow] -- Distributed hrow
  139. //
  140. // History: 11-sept-2000 slarimor Created.
  141. //
  142. //----------------------------------------------------------------------------
  143. void CHRowManager::AddRef( HROW hrow )
  144. {
  145. unsigned iCurrent = ConvertAndValidate( hrow );
  146. _aHRow[iCurrent].AddRef();
  147. }
  148. //+---------------------------------------------------------------------------
  149. //
  150. // Member: CHRowManager::Release, public
  151. //
  152. // Synopsis: De-refs a given hrow
  153. //
  154. // Arguments: [hrow] -- Distributed hrow
  155. //
  156. // History: 05-Jun-95 KyleP Created.
  157. //
  158. //----------------------------------------------------------------------------
  159. void CHRowManager::Release( HROW hrow )
  160. {
  161. unsigned iCurrent = ConvertAndValidate( hrow );
  162. _aHRow[iCurrent].Release();
  163. if ( !_aHRow[iCurrent].IsInUse() )
  164. {
  165. _aHRow[iCurrent].Link( _iFirstFree );
  166. _iFirstFree = iCurrent;
  167. }
  168. }
  169. //+---------------------------------------------------------------------------
  170. //
  171. // Member: CHRowManager::IsSame, public
  172. //
  173. // Synopsis: Compares HROWs.
  174. //
  175. // Arguments: [hrow1] -- Distributed hrow
  176. // [hrow1] -- Distributed hrow
  177. //
  178. // Returns: FALSE. We can't compare rows right now.
  179. //
  180. // History: 05-Jun-95 KyleP Created.
  181. //
  182. //----------------------------------------------------------------------------
  183. BOOL CHRowManager::IsSame( HROW hrow1, HROW hrow2 )
  184. {
  185. // NTRAID#DB-NTBUG9-84054-2000/07/31-dlee Distributed queries don't implement hrow identity IsSame() method
  186. return( FALSE );
  187. }
  188. //+---------------------------------------------------------------------------
  189. //
  190. // Member: CHRowManager::Grow, private
  191. //
  192. // Synopsis: Grow HROW free space.
  193. //
  194. // History: 05-Jun-95 KyleP Created.
  195. //
  196. //----------------------------------------------------------------------------
  197. void CHRowManager::Grow()
  198. {
  199. //
  200. // Allocate new array.
  201. //
  202. unsigned cTemp = _cHRow * 2;
  203. CHRow * pTemp = new CHRow [cTemp];
  204. //
  205. // Transfer old data.
  206. //
  207. RtlCopyMemory( pTemp, _aHRow, _cHRow * sizeof(_aHRow[0]) );
  208. //
  209. // Link new elements into free list.
  210. //
  211. Win4Assert( _iFirstFree == -1 );
  212. for ( unsigned i = _cHRow; i < cTemp-1; i++ )
  213. {
  214. pTemp[i].Link( i + 1 );
  215. }
  216. pTemp[cTemp-1].Link( -1 );
  217. //
  218. // Out with the old, and in with the new.
  219. //
  220. delete [] _aHRow;
  221. _aHRow = pTemp;
  222. //
  223. // And now the same thing for the hint. Note that we've completely taken
  224. // care of memory leaks for _aHRow before moving on to the hints.
  225. //
  226. if ( IsTrackingSiblings() )
  227. {
  228. HROW * pTempHint = new HROW [cTemp * _cChild];
  229. RtlCopyMemory( pTempHint, _ahrowHint, _cHRow*_cChild*sizeof(_ahrowHint[0]) );
  230. delete [] _ahrowHint;
  231. _ahrowHint = pTempHint;
  232. }
  233. _iFirstFree = _cHRow;
  234. _cHRow = cTemp;
  235. } //Grow