-- Copyright (C) 1981, 1984, 1985  by Xerox Corporation. All rights reserved. 
-- HeapXDefs.mesa, private DEFS for heap storage

-- HGM, 15-Sep-85 12:51:50
-- Andrew Birrell	24-Feb-81 15:47:29 --
-- Brenda Hankins	15-Aug-84 14:11:34	alter WriterData def.

DIRECTORY
  HeapDefs USING [ObjectNumber, ObjectOffset],
  VMDefs USING [FullAddress, PageAddress, Page, PageIndex, LookAheadCount];

HeapXDefs: DEFINITIONS =
  BEGIN


  -- Layout of objects on disk --

  ObjectHeader: TYPE = MACHINE DEPENDENT RECORD [
    size: CARDINAL, number: HeapDefs.ObjectNumber];

  PageHeader: TYPE = MACHINE DEPENDENT RECORD [offset: HeapDefs.ObjectOffset];


  -- Writer --

  WriterHandle: TYPE = LONG POINTER TO WriterData;
  WriterData: TYPE = MONITORED RECORD [
    next: WriterHandle,  -- free chain --
    page: VMDefs.Page,
    object: HeapDefs.ObjectNumber,
    offset: HeapDefs.ObjectOffset,
    maxOffset: HeapDefs.ObjectOffset,  -- max offset if reWriting
    start: VMDefs.PageAddress,  -- first value of wPos.page --
    reWriting: BOOLEAN,
    base: VMDefs.PageIndex,  --start of sub-object data--
    wPos: VMDefs.FullAddress,
    objectHead: LONG POINTER TO ObjectHeader];


  -- Reader --

  ReaderHandle: TYPE = LONG POINTER TO ReaderData;

  ReaderData: TYPE = MONITORED RECORD [
    next: ReaderHandle,
    page: VMDefs.Page,
    object: HeapDefs.ObjectNumber,
    offset: HeapDefs.ObjectOffset,
    where: VMDefs.FullAddress,
    end: BOOLEAN,
    stopped: BOOLEAN,
    canStart: CONDITION];

  lookAhead: VMDefs.LookAheadCount = 2;
  -- used by readers and compactor --


  -- Compactor interlock --

  StopAllReaders: PROCEDURE [HeapDefs.ObjectNumber];
  -- Stops any reader which is reading this object. --

  RestartAllReaders: PROCEDURE [HeapDefs.ObjectNumber];
  -- Allows stopped readers to continue; the object may have moved in the
  -- heap. --

  StopReader: PROCEDURE [from: ReaderHandle];
  -- Tells the reader to stop. --

  RestartReader: PROCEDURE [from: ReaderHandle];
  -- Tells the reader to restart and re-calculate its position within the
  -- heap, since the object may have moved. --

  END.