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

  1. /***
  2. * vmlock.c -
  3. *
  4. *       Copyright (c) 1989-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *
  8. * PUBLIC Functions:
  9. *
  10. *       PVmLockVp:
  11. *       This function locks the page containing the specified virtual
  12. *       address using PVmLockVpCb.
  13. *
  14. *       VmUnlockVp:
  15. *       This function unlocks the page containing the specified virtual
  16. *       address using VmUnlockVpCb.
  17. *
  18. *******************************************************************************/
  19.  
  20. #pragma title("Virtual Memory Manager")
  21. #pragma subtitle("Locking functions")
  22.  
  23. #include <version.h>
  24. #include <vmassert.h>
  25. #include <system.h>
  26. #include <error.h>
  27. #include <vm.h>
  28. #include <vmp.h>
  29.  
  30. #include <limits.h>
  31. #include <stddef.h>
  32.  
  33. unsigned _near _timeCur;               /* Current timestamp value */
  34.  
  35. #pragma page()
  36.  
  37. PVOID PUBLIC __PVmLockVp(VPVOID vp)
  38. {
  39.    PVOID pv;
  40.    HPGD  hpgd;
  41.  
  42.    VmTracePrintf(("PVmLockVp: vp = %08lX.\n", vp));
  43.  
  44.    pv = __PVmLoadVp(vp, FALSE);
  45.    if (pv == NULL)
  46.       return(NULL);
  47.  
  48.    hpgd = __HpgdSearchCache(vp);
  49.    Assert(hpgd != hpgdNil);
  50.  
  51.    PpgdOfHpgd(hpgd)->cLock++;
  52.  
  53.    return(pv);
  54. }
  55.  
  56.  
  57. #pragma page()
  58.  
  59. void PUBLIC __VmUnlockVp(VPVOID vp, int fDirty)
  60. {
  61.    HPGD  hpgd;
  62.  
  63.    VmTracePrintf(("VmUnlockVp: vp = %08lX, fDirty = %u.\n", vp, fDirty));
  64.  
  65.    hpgd = __HpgdSearchCache(vp);
  66.    Assert(hpgd != hpgdNil);
  67.  
  68.    Assert(PpgdOfHpgd(hpgd)->cLock != 0);
  69.    PpgdOfHpgd(hpgd)->cLock--;
  70.  
  71.    if (++_timeCur == UINT_MAX)
  72.       __VmUpdateTimestamps();
  73.  
  74.    PpgdOfHpgd(hpgd)->timeRef = _timeCur;
  75.  
  76.    if (fDirty)                         /* Mark page as dirty if requested */
  77.       PpgdOfHpgd(hpgd)->Flags |= fDirtyPgd;
  78. }
  79.