home *** CD-ROM | disk | FTP | other *** search
- /***
- *listmgt.c - List management routines
- *
- * Copyright (c) 1989-1992, Microsoft Corporation. All rights reserved.
- *
- *******************************************************************************/
-
- #include <version.h>
- #include <vmassert.h>
- #include <stdlib.h>
- #include <vmm.h>
- #include <vmbm.h>
-
-
- /*** VmFreeLink
- *
- * Purpose: To Link two ends of a free list together
- *
- * Input:
- * hbkBack -The lower free block
- * hbkNext -The higher free block
- *
- * Output:
- *
- * Exceptions:
- *
- * Notes:
- *
- * This may cause 2 page swaps
- *
- *************************************************************************/
- void VMFUNC __VmFreeLink(
- HBK hbkBack,
- HBK hbkNext
- ) {
- PHDF phdf;
-
- if( hbkBack ) {
- phdf = __PVmLoadVp((VPVOID) hbkBack, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkNextHdf = hbkNext;
- }
- else
- _gvmbm.hbkFreeStart = hbkNext;
-
- if( hbkNext ) {
- phdf = __PVmLoadVp((VPVOID) hbkNext, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkBackHdf = hbkBack;
- }
- else
- _gvmbm.hbkFreeLast = hbkBack;
- }
-
-
-
- /*** VmFreeLinkIn
- *
- * Purpose: To Link two ends of a free list together
- *
- * Input:
- * hbkNew -The new free block to link in
- * cb -The size of the new free block
- * hbkBack -The lower free block
- * hbkNext -The higher free block
- *
- * Output:
- *
- * Exceptions:
- *
- * Notes:
- *
- * hbkNew may already be loaded, so the load will be cheap
- *
- * This may cause 3 page swaps, usually 2 or less because hbkNew is usually
- * already loaded.
- *
- *************************************************************************/
- void VMFUNC __VmFreeLinkIn(
- HBK hbkNew,
- unsigned cb,
- HBK hbkBack,
- HBK hbkNext
- ) {
- PHDF phdf;
-
- phdf = __PVmLoadVp((VPVOID) hbkNew, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkBackHdf = hbkBack;
- phdf->hbkNextHdf = hbkNext;
- Assert( CbGetSize(phdf->cbSize) == cb );
-
- if( hbkBack ) {
- phdf = __PVmLoadVp((VPVOID) hbkBack, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkNextHdf = hbkNew;
- }
- else
- _gvmbm.hbkFreeStart = hbkNew;
-
- if( hbkNext ) {
- phdf = __PVmLoadVp((VPVOID) hbkNext, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkBackHdf = hbkNew;
- }
- else
- _gvmbm.hbkFreeLast = hbkNew;
-
- // update the free list info
- _gvmbm.cFree++;
- if( cb > _gvmbm.cbMaxFree )
- _gvmbm.cbMaxFree = cb;
-
- }
-
-
- /*** VmFreeLinkEnd
- *
- * Purpose: Put a new free block at the end of the free list
- *
- * Input:
- * hbkNew -The new free block to link in
- * cb -The size of the new free block
- *
- * Output:
- *
- * Exceptions:
- *
- * Notes:
- *
- * May cause 1 page swap
- *
- * For optimization, the free page may already be loaded so
- * make sure the free page is operated on first (hbkNew)
- *
- *************************************************************************/
- void VMFUNC __VmFreeLinkEnd(
- HBK hbkNew,
- unsigned cb
- ) {
- PHDF phdf;
-
- phdf = __PVmLoadVp((VPVOID) hbkNew, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- phdf->hbkBackHdf = _gvmbm.hbkFreeLast;
- phdf->hbkNextHdf = NULL;
-
- // if there is a back free page update it
- if( _gvmbm.hbkFreeLast ) {
- phdf = __PVmLoadVp((VPVOID) _gvmbm.hbkFreeLast, TRUE);
- Assert( phdf != NULL && phdf->fFree == TRUE );
- Assert( phdf->hbkNextHdf == NULL );
- phdf->hbkNextHdf = hbkNew;
- }
-
- _gvmbm.hbkFreeLast = hbkNew;
- if( !_gvmbm.hbkFreeStart )
- _gvmbm.hbkFreeStart = _gvmbm.hbkFreeLast;
-
- _gvmbm.cFree++;
- if( cb > _gvmbm.cbMaxFree )
- _gvmbm.cbMaxFree = cb;
- }
-