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.

184 lines
5.4 KiB

  1. /* JET API flags
  2. /**/
  3. #define FPIBVersion( ppib ) (!((ppib)->grbit & (JET_bitCIMCommitted | JET_bitCIMDirty)))
  4. #define FPIBCommitted( ppib ) ((ppib)->grbit & JET_bitCIMCommitted)
  5. #define FPIBDirty( ppib ) ((ppib)->grbit & JET_bitCIMDirty)
  6. #define FPIBAggregateTransaction( ppib ) ((ppib)->grbit & JET_bitAggregateTransaction)
  7. #define FPIBBMClean( ppib ) ((ppib)->fBMCleanProc )
  8. #define PIBSetBMClean( ppib ) ((ppib)->fBMCleanProc = 1 )
  9. #define PIBResetBMClean( ppib ) ((ppib)->fBMCleanProc = 0 )
  10. //
  11. // Process Information Block
  12. //
  13. struct _pib
  14. {
  15. /* most used field has offset 0
  16. /**/
  17. TRX trxBegin0; // trx id
  18. TRX trxCommit0;
  19. /* JET API fields
  20. /**/
  21. JET_SESID sesid; // JET session id
  22. JET_GRBIT grbit; // session flags
  23. struct _pib *ppibNext; // PIB list
  24. LEVEL level; // transaction level of this session
  25. LEVEL levelRollback; // transaction level which must be rolled back
  26. struct _dab *pdabList; // list of open DAB's of this thread
  27. USHORT rgcdbOpen[dbidMax]; // counter for open databases
  28. struct _fucb *pfucb; // list of active fucb of this thread
  29. /* logging/recovery fields
  30. /**/
  31. PROCID procid; // thread id
  32. LGPOS lgposStart; // log time
  33. LEVEL levelBegin; // transaction level when first begin transaction operation
  34. LEVEL levelDeferBegin; // count of deferred open transactions
  35. SIG sigWaitLogFlush;
  36. LONG lWaitLogFlush;
  37. LONG grbitsCommitDefault;
  38. struct _pib *ppibNextWaitFlush;
  39. struct _pib *ppibPrevWaitFlush;
  40. LGPOS lgposPrecommit0; // level 0 precommit record position.
  41. /* flags
  42. /**/
  43. BOOL fUserSession:1; // user session
  44. BOOL fAfterFirstBT:1; // for redo only
  45. BOOL fLGWaiting:1; // waiting for log to flush
  46. BOOL fBMCleanProc:1; // session is for doing BMCleanup
  47. // BOOL fDeferFreeNodeSpace:1; // session has deferred node free space
  48. BOOL fPrecommit:1; // in precommit state? Recovery only
  49. BOOL fBegin0Logged:1; // begin transaction has logged
  50. BOOL fSetAttachDB:1; // set up attachdb.
  51. BOOL fMacroGoing:1;
  52. BOOL levelMacro:4;
  53. /* version store fields
  54. /**/
  55. RCE *prceNewest; // newest RCE of session
  56. #ifdef DEBUG
  57. DWORD dwLogThreadId;
  58. #endif
  59. /* counters for the session.
  60. */
  61. LONG cAccessPage; // counter of page access.
  62. LONG cLatchConflict; // counter of page latch conflicts.
  63. LONG cSplitRetry; // counter of split retries.
  64. LONG cNeighborPageScanned; // counter of neighboring page scanned.
  65. union {
  66. struct { // Redo only.
  67. BYTE *rgbLogRec;
  68. WORD cbLogRecMac;
  69. WORD ibLogRecAvail;
  70. };
  71. struct { // Do only
  72. /* array for internal macro operations.
  73. */
  74. struct _bf **rgpbfLatched; // dynamically allocated array
  75. WORD cpbfLatchedMac; // for macro operations.
  76. WORD ipbfLatchedAvail; // for macro operations.
  77. };
  78. };
  79. #ifdef PCACHE_OPTIMIZATION
  80. /* pad to multiple of 32 bytes
  81. /**/
  82. #ifdef DEBUG
  83. BYTE rgbFiller[0];
  84. #else
  85. BYTE rgbFiller[4];
  86. #endif
  87. #endif
  88. };
  89. #define PpibMEMAlloc() (PIB*)PbMEMAlloc(iresPIB)
  90. #ifdef DEBUG /* Debug check for illegal use of freed pib */
  91. #define MEMReleasePpib(ppib) { MEMRelease(iresPIB, (BYTE*)(ppib)); ppib = ppibNil; }
  92. #else
  93. #define MEMReleasePpib(ppib) { MEMRelease(iresPIB, (BYTE*)(ppib)); }
  94. #endif
  95. extern PIB *ppibGlobal;
  96. extern PIB *ppibGlobalMin;
  97. extern PIB *ppibGlobalMax;
  98. PROCID ProcidPIBOfPpib( PIB *ppib );
  99. STATIC INLINE PROCID ProcidPIBOfPpib( PIB *ppib )
  100. {
  101. return (PROCID)(((BYTE *)ppib - (BYTE *)ppibGlobalMin)/sizeof(PIB));
  102. }
  103. STATIC INLINE PIB *PpibOfProcid( PROCID procid )
  104. {
  105. return ppibGlobalMin + procid;
  106. }
  107. /* PIB validation
  108. /**/
  109. #define ErrPIBCheck( ppib ) \
  110. ( ( ppib >= ppibGlobalMin \
  111. && ppib < ppibGlobalMax \
  112. && ( ( (BYTE *)ppib - (BYTE *)ppibGlobalMin ) % sizeof(PIB) ) == 0 \
  113. && ppib->procid == ProcidPIBOfPpib( ppib ) ) \
  114. ? JET_errSuccess : JET_errInvalidSesid )
  115. #define CheckPIB( ppib ) \
  116. Assert( ErrPIBCheck( ppib ) == JET_errSuccess \
  117. && (ppib)->level < levelMax )
  118. #if 0
  119. #define FPIBDeferFreeNodeSpace( ppib ) ( (ppib)->fDeferFreeNodeSpace )
  120. #define PIBSetDeferFreeNodeSpace( ppib ) ( (ppib)->fDeferFreeNodeSpace = fTrue )
  121. #define PIBResetDeferFreeNodeSpace( ppib ) ( (ppib)->fDeferFreeNodeSpace = fFalse )
  122. #endif
  123. #define FPIBActive( ppib ) ( (ppib)->level != levelNil )
  124. #define SesidOfPib( ppib ) ( (ppib)->sesid )
  125. /* prototypes
  126. /**/
  127. LONG CppibPIBUserSessions( VOID );
  128. VOID RecalcTrxOldest( );
  129. ERR ErrPIBBeginSession( PIB **pppib, PROCID procid );
  130. VOID PIBEndSession( PIB *ppib );
  131. #ifdef DEBUG
  132. VOID PIBPurge( VOID );
  133. #else
  134. #define PIBPurge()
  135. #endif
  136. #define PIBUpdatePrceNewest( ppib, prce ) \
  137. { \
  138. if ( (ppib)->prceNewest == (prce) ) \
  139. { \
  140. Assert( (prce)->prceNextOfSession == prceNil ); \
  141. (ppib)->prceNewest = prceNil; \
  142. } \
  143. }
  144. #define PIBSetPrceNewest( ppib, prce ) \
  145. { \
  146. (ppib)->prceNewest = (prce); \
  147. }
  148. #define PIBSetLevelRollback( ppib, levelT ) \
  149. { \
  150. Assert( (levelT) > levelMin && \
  151. (levelT) < levelMax ); \
  152. Assert( (ppib)->levelRollback >= levelMin && \
  153. (ppib)->levelRollback < levelMax ); \
  154. if ( levelT < (ppib)->levelRollback ) \
  155. (ppib)->levelRollback = (levelT); \
  156. }