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.

225 lines
5.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: segmru.cxx
  7. //
  8. // Contents: Most Recently Used segments management.
  9. //
  10. // Classes: CMRUSegments
  11. //
  12. // History: 4-11-95 srikants Created
  13. //
  14. //
  15. // Notes : All methods in this are assumed to be under a larger
  16. // lock (like the bigtable lock).
  17. //
  18. //----------------------------------------------------------------------------
  19. #include "pch.cxx"
  20. #pragma hdrstop
  21. #include <segmru.hxx>
  22. #include <tableseg.hxx>
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: CMRUSegments
  26. //
  27. // Synopsis: Destructor for the most recently used segments list.
  28. //
  29. // History: 4-11-95 srikants Created
  30. //
  31. // Notes:
  32. //
  33. //----------------------------------------------------------------------------
  34. CMRUSegments::~CMRUSegments()
  35. {
  36. for ( CWidSegmentMap * pEntry = _list.RemoveLast();
  37. 0 != pEntry;
  38. pEntry = _list.RemoveLast() )
  39. {
  40. delete pEntry;
  41. }
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Function: IsSegmentInUse
  46. //
  47. // Synopsis: Tests if the given segment is currently in use or not.
  48. //
  49. // Arguments: [pSegment] - Segment to test.
  50. //
  51. // Returns: TRUE if the segment is in use. FALSE o/w
  52. //
  53. // History: 4-11-95 srikants Created
  54. //
  55. // Notes:
  56. //
  57. //----------------------------------------------------------------------------
  58. BOOL CMRUSegments::IsSegmentInUse( CTableSegment * pSegment )
  59. {
  60. Win4Assert( 0 != pSegment );
  61. for ( CFwdWidSegMapIter iter(_list); !_list.AtEnd(iter);
  62. _list.Advance(iter) )
  63. {
  64. if ( iter->GetWorkId() != widInvalid )
  65. {
  66. if ( iter->GetSegment() == pSegment ||
  67. pSegment->IsRowInSegment( iter->GetWorkId()) )
  68. {
  69. return TRUE;
  70. }
  71. }
  72. }
  73. return FALSE;
  74. }
  75. //+---------------------------------------------------------------------------
  76. //
  77. // Function: AddReplace
  78. //
  79. // Synopsis: Add/Replaces the wid/segment mapping entry in the MRU list.
  80. //
  81. // Arguments: [wid] - Workid of the new entry
  82. // [pSeg] - Pointer to the segment in which the wid is present.
  83. // If it is set to NULL, it just means that the wid
  84. // is going to be used but we don't know in which segment
  85. // it is present (during Bucket->Window conversion)
  86. //
  87. // History: 4-11-95 srikants Created
  88. //
  89. // Notes:
  90. //
  91. //----------------------------------------------------------------------------
  92. void CMRUSegments::AddReplace( WORKID wid, CTableSegment * pSeg )
  93. {
  94. Win4Assert( widInvalid != wid );
  95. //
  96. // Determine if the workid already exists in the list of MRU wids.
  97. // If so, just move it to the top of the list.
  98. //
  99. for ( CFwdWidSegMapIter iter(_list); !_list.AtEnd(iter);
  100. _list.Advance(iter) )
  101. {
  102. if ( wid == iter->GetWorkId() )
  103. {
  104. CWidSegmentMap * pCurrent = iter.GetEntry();
  105. _list.MoveToFront( pCurrent );
  106. pCurrent->Set( pSeg );
  107. return;
  108. }
  109. }
  110. //
  111. // We either need to remove an entry from the end or create a new one
  112. // and add
  113. //
  114. CWidSegmentMap * pEntry = 0;
  115. if ( _list.Count() < _nMaxEntries )
  116. {
  117. pEntry = new CWidSegmentMap( wid, pSeg );
  118. }
  119. else
  120. {
  121. //
  122. // Remove the last entry from the list and re-use it for
  123. // the new entry.
  124. //
  125. pEntry = _list.RemoveLast();
  126. }
  127. Win4Assert( 0 != pEntry );
  128. pEntry->Set( wid, pSeg );
  129. _list.Push(pEntry);
  130. return;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Function: Invalidate
  135. //
  136. // Synopsis: Invalidate all cached pointers that are same as the given
  137. // one.
  138. //
  139. // Arguments: [pSegment] - The segment that is going to be invalid.
  140. //
  141. // History: 4-11-95 srikants Created
  142. //
  143. // Notes:
  144. //
  145. //----------------------------------------------------------------------------
  146. void CMRUSegments::Invalidate( const CTableSegment * const pSegment )
  147. {
  148. Win4Assert( 0 != pSegment );
  149. for ( CFwdWidSegMapIter iter(_list); !_list.AtEnd(iter);
  150. _list.Advance(iter) )
  151. {
  152. if ( iter->GetSegment() == pSegment )
  153. {
  154. iter->Set(0);
  155. }
  156. }
  157. }
  158. //+---------------------------------------------------------------------------
  159. //
  160. // Function: Remove
  161. //
  162. // Synopsis:
  163. //
  164. // Arguments: [wid] -
  165. //
  166. // Returns:
  167. //
  168. // Modifies:
  169. //
  170. // History: 5-30-95 srikants Created
  171. //
  172. // Notes:
  173. //
  174. //----------------------------------------------------------------------------
  175. void CMRUSegments::Remove( WORKID wid )
  176. {
  177. Win4Assert( widInvalid != wid );
  178. //
  179. // Determine if the workid already exists in the list of MRU wids.
  180. // If so, just move it to the top of the list.
  181. //
  182. CFwdWidSegMapIter iter(_list);
  183. while ( !_list.AtEnd(iter) )
  184. {
  185. CWidSegmentMap * pCurrent = iter.GetEntry();
  186. //
  187. // Because we may destroy the current node, we must skip ahead
  188. // before destorying it.
  189. //
  190. _list.Advance(iter);
  191. if ( wid == pCurrent->GetWorkId() )
  192. {
  193. _list.RemoveFromList( pCurrent );
  194. delete pCurrent;
  195. }
  196. }
  197. return;
  198. }