home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / vm / src / listmgt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-15  |  3.7 KB  |  164 lines

  1. /***
  2. *listmgt.c - List management routines
  3. *
  4. *       Copyright (c) 1989-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *******************************************************************************/
  7.  
  8. #include <version.h>
  9. #include <vmassert.h>
  10. #include <stdlib.h>
  11. #include <vmm.h>
  12. #include <vmbm.h>
  13.  
  14.  
  15. /*** VmFreeLink
  16. *
  17. * Purpose:  To Link two ends of a free list together
  18. *
  19. * Input:
  20. *       hbkBack -The lower free block
  21. *       hbkNext -The higher free block
  22. *
  23. * Output:
  24. *
  25. * Exceptions:
  26. *
  27. * Notes:
  28. *
  29. *   This may cause 2 page swaps
  30. *
  31. *************************************************************************/
  32. void VMFUNC __VmFreeLink(
  33. HBK hbkBack,
  34. HBK hbkNext
  35. ) {
  36. PHDF    phdf;
  37.  
  38. if( hbkBack ) {
  39.     phdf = __PVmLoadVp((VPVOID) hbkBack, TRUE);
  40.     Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  41.     phdf->hbkNextHdf = hbkNext;
  42.     }
  43. else
  44.     _gvmbm.hbkFreeStart = hbkNext;
  45.  
  46. if( hbkNext ) {
  47.     phdf = __PVmLoadVp((VPVOID) hbkNext, TRUE);
  48.     Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  49.     phdf->hbkBackHdf = hbkBack;
  50.     }
  51. else
  52.     _gvmbm.hbkFreeLast = hbkBack;
  53. }
  54.  
  55.  
  56.  
  57. /*** VmFreeLinkIn
  58. *
  59. * Purpose:  To Link two ends of a free list together
  60. *
  61. * Input:
  62. *       hbkNew  -The new free block to link in
  63. *       cb      -The size of the new free block
  64. *       hbkBack -The lower free block
  65. *       hbkNext -The higher free block
  66. *
  67. * Output:
  68. *
  69. * Exceptions:
  70. *
  71. * Notes:
  72. *
  73. *   hbkNew may already be loaded, so the load will be cheap
  74. *
  75. *   This may cause 3 page swaps, usually 2 or less because hbkNew is usually
  76. *   already loaded.
  77. *
  78. *************************************************************************/
  79. void VMFUNC __VmFreeLinkIn(
  80. HBK         hbkNew,
  81. unsigned    cb,
  82. HBK         hbkBack,
  83. HBK         hbkNext
  84. ) {
  85. PHDF    phdf;
  86.  
  87. phdf = __PVmLoadVp((VPVOID) hbkNew, TRUE);
  88. Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  89. phdf->hbkBackHdf    = hbkBack;
  90. phdf->hbkNextHdf    = hbkNext;
  91. Assert( CbGetSize(phdf->cbSize) == cb );
  92.  
  93. if( hbkBack ) {
  94.     phdf = __PVmLoadVp((VPVOID) hbkBack, TRUE);
  95.     Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  96.     phdf->hbkNextHdf = hbkNew;
  97.     }
  98. else
  99.     _gvmbm.hbkFreeStart = hbkNew;
  100.  
  101. if( hbkNext ) {
  102.     phdf = __PVmLoadVp((VPVOID) hbkNext, TRUE);
  103.     Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  104.     phdf->hbkBackHdf = hbkNew;
  105.     }
  106. else
  107.     _gvmbm.hbkFreeLast = hbkNew;
  108.  
  109. // update the free list info
  110. _gvmbm.cFree++;
  111. if( cb > _gvmbm.cbMaxFree )
  112.     _gvmbm.cbMaxFree = cb;
  113.  
  114. }
  115.  
  116.  
  117. /*** VmFreeLinkEnd
  118. *
  119. * Purpose:  Put a new free block at the end of the free list
  120. *
  121. * Input:
  122. *       hbkNew  -The new free block to link in
  123. *       cb      -The size of the new free block
  124. *
  125. * Output:
  126. *
  127. * Exceptions:
  128. *
  129. * Notes:
  130. *
  131. *       May cause 1 page swap
  132. *
  133. *       For optimization, the free page may already be loaded so
  134. *       make sure the free page is operated on first (hbkNew)
  135. *
  136. *************************************************************************/
  137. void VMFUNC __VmFreeLinkEnd(
  138. HBK         hbkNew,
  139. unsigned    cb
  140. ) {
  141. PHDF    phdf;
  142.  
  143. phdf = __PVmLoadVp((VPVOID) hbkNew, TRUE);
  144. Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  145. phdf->hbkBackHdf        = _gvmbm.hbkFreeLast;
  146. phdf->hbkNextHdf        = NULL;
  147.  
  148. // if there is a back free page update it
  149. if( _gvmbm.hbkFreeLast ) {
  150.     phdf = __PVmLoadVp((VPVOID) _gvmbm.hbkFreeLast, TRUE);
  151.     Assert( phdf != NULL  &&  phdf->fFree == TRUE );
  152.     Assert( phdf->hbkNextHdf == NULL );
  153.     phdf->hbkNextHdf    = hbkNew;
  154.     }
  155.  
  156. _gvmbm.hbkFreeLast = hbkNew;
  157. if( !_gvmbm.hbkFreeStart )
  158.     _gvmbm.hbkFreeStart = _gvmbm.hbkFreeLast;
  159.  
  160. _gvmbm.cFree++;
  161. if( cb > _gvmbm.cbMaxFree )
  162.     _gvmbm.cbMaxFree = cb;
  163. }
  164.