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.

262 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: FRETEST.HXX
  7. //
  8. // Contents: Fresh test object
  9. //
  10. // Classes: CFreshTest
  11. //
  12. // History: 01-Oct-91 BartoszM Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <fretable.hxx>
  17. class CWidArray;
  18. class CDocList;
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CFreshTest
  22. //
  23. // Purpose: Tests the freshness of the index id <-> work id association
  24. //
  25. // History: 16-May-91 BartoszM Created.
  26. //
  27. //----------------------------------------------------------------------------
  28. class CFreshTest
  29. {
  30. public:
  31. CFreshTest ( unsigned size );
  32. CFreshTest ( CFreshTest& source, CWidArray& widTable );
  33. CFreshTest ( CFreshTest& source, CIdxSubstitution& subst);
  34. CFreshTest( CFreshTest& source );
  35. unsigned Count() { return _freshTable.Count(); }
  36. unsigned DeleteCount() { return _cDeletes; }
  37. void DecrementDeleteCount( unsigned cDeletes )
  38. {
  39. _cDeletes -= cDeletes;
  40. }
  41. void Add ( WORKID wid, INDEXID iid )
  42. {
  43. _freshTable.Add ( wid, iid );
  44. }
  45. void AddReplace ( WORKID wid, INDEXID iid )
  46. {
  47. _freshTable.AddReplace ( wid, iid );
  48. }
  49. void AddReplaceDelete ( WORKID wid, INDEXID iidDeleted )
  50. {
  51. //
  52. // NOTE: _cDeletes can be artificially high, if we get double-deletions
  53. // but this doesn't really hurt, just possibly leads to an extra
  54. // delete merge occasionally. So why waste the time filtering
  55. // out the double-deletes?
  56. //
  57. INDEXID iidOld = _freshTable.AddReplace ( wid, iidDeleted );
  58. if ( iidOld != iidDeleted1 && iidOld != iidDeleted2 )
  59. _cDeletes++;
  60. }
  61. void ModificationsComplete() { _freshTable.ModificationsComplete(); }
  62. enum IndexSource
  63. {
  64. Invalid,
  65. Unknown,
  66. Master,
  67. Shadow
  68. };
  69. IndexSource IsCorrectIndex( INDEXID iid, WORKID wid );
  70. BOOL InUse() { return _refCount != 0; }
  71. void Reference() { _refCount++; }
  72. ULONG Dereference() { return --_refCount; }
  73. CFreshTable * GetFreshTable() { Reference(); return &_freshTable; }
  74. void ReleaseFreshTable(CFreshTable *p) { if (p != 0) Dereference(); }
  75. INDEXID Find ( WORKID wid );
  76. #ifdef CIEXTMODE
  77. void CiExtDump(void *ciExtSelf);
  78. #endif
  79. private:
  80. ULONG RefCount() { return _refCount; } // for debugging only
  81. void PatchEntry ( CFreshItem* pEntry, INDEXID iid );
  82. ULONG _refCount;
  83. CFreshTable _freshTable;
  84. unsigned _cDeletes;
  85. };
  86. //+-------------------------------------------------------------------------
  87. //
  88. // Class: CFreshTestLock
  89. //
  90. // Synopsis: A lock smart pointer on a CFreshTest object.
  91. // Note that the destructor only de-references the fresh test
  92. // It does NOT destroy the fresh test.
  93. //
  94. // History: 94-Mar-31 DwightKr Created
  95. //
  96. //--------------------------------------------------------------------------
  97. class CFreshTestLock
  98. {
  99. public:
  100. inline CFreshTestLock( CFreshTest * );
  101. inline CFreshTestLock();
  102. inline ~CFreshTestLock();
  103. inline CFreshTest * operator->() { return _pFreshTest; }
  104. inline CFreshTest & operator*() { return *_pFreshTest; }
  105. private:
  106. CFreshTest * _pFreshTest;
  107. };
  108. //+-------------------------------------------------------------------------
  109. //
  110. // Class: SFreshTable
  111. //
  112. // Synopsis: A smart pointer to a CFreshTable object
  113. //
  114. // History: 94-Jan-19 DwightKr Created
  115. //
  116. //--------------------------------------------------------------------------
  117. class SFreshTable
  118. {
  119. public:
  120. inline SFreshTable( CFreshTest & );
  121. inline ~SFreshTable();
  122. inline CFreshTable * operator->() { return _pFreshTable; }
  123. inline CFreshTable & operator*() { return *_pFreshTable; }
  124. private:
  125. CFreshTable * _pFreshTable;
  126. CFreshTest & _freshTest;
  127. };
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Member: CFreshTest::PatchEntry, private
  131. //
  132. // Synopsis: During recovery, if the wordlist
  133. // has not been recreated yet, patch the entry
  134. //
  135. // Arguments: [fresh] -- fresh table
  136. //
  137. // History: 08-Oct-91 BartoszM Created.
  138. //
  139. // Notes: The assumption is that the operation is atomic.
  140. // If there is a race to patch, the last query
  141. // wins, but it doesn't really matter.
  142. //
  143. //----------------------------------------------------------------------------
  144. inline void CFreshTest::PatchEntry ( CFreshItem* pEntry, INDEXID iid )
  145. {
  146. ciDebugOut (( DEB_ITRACE, "FreshTest: patching entry %ld\n", iid ));
  147. pEntry->SetIndexId ( iid );
  148. }
  149. //+---------------------------------------------------------------------------
  150. //----------------------------------------------------------------------------
  151. inline INDEXID CFreshTest::Find ( WORKID wid )
  152. {
  153. INDEXID iid = iidInvalid; // Assume it's in the master index
  154. Reference();
  155. CFreshItem *freshEntry = _freshTable.Find( wid );
  156. if (0 != freshEntry)
  157. {
  158. iid = freshEntry->IndexId();
  159. }
  160. Dereference();
  161. return iid;
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Member: CFreshTestLock::CFreshTestLock, public
  166. //
  167. // Synopsis: Constructor.
  168. //
  169. // Arguments: [frestTest] -- freshTest to encapsulate
  170. //
  171. // History: 94-Mar-31 DwightKr Created.
  172. //
  173. //----------------------------------------------------------------------------
  174. CFreshTestLock::CFreshTestLock( CFreshTest * pFreshTest) : _pFreshTest(pFreshTest)
  175. {
  176. }
  177. CFreshTestLock::CFreshTestLock()
  178. : _pFreshTest( 0 )
  179. {
  180. }
  181. CFreshTestLock::~CFreshTestLock()
  182. {
  183. if ( _pFreshTest )
  184. _pFreshTest->Dereference();
  185. }
  186. //+---------------------------------------------------------------------------
  187. //
  188. // Member: SFreshTable::SFreshTable, public
  189. //
  190. // Synopsis: Constructor.
  191. //
  192. // Arguments: [frestTest] -- freshTest which owns the freshTable
  193. //
  194. // History: 94-Jan-19 DwightKr Created.
  195. //
  196. //----------------------------------------------------------------------------
  197. SFreshTable::SFreshTable( CFreshTest & freshTest) : _freshTest(freshTest),
  198. _pFreshTable(0)
  199. {
  200. _pFreshTable = _freshTest.GetFreshTable();
  201. }
  202. SFreshTable::~SFreshTable()
  203. {
  204. _freshTest.ReleaseFreshTable(_pFreshTable);
  205. }