-- RTStorageAccounting.Mesa
-- last edited September 23, 1982 10:37 am by Paul Rovner

DIRECTORY
PSB USING[PsbIndex],
RTRefCounts USING[InternalReclaim],
RTOS USING[GetCurrent];

RTStorageAccounting: DEFINITIONS
IMPORTS RTOS, RTRefCounts
= BEGIN

-- TYPES
PSBIMap: TYPE = RECORD[elements: SEQUENCE maxLength: CARDINAL OF CellCount];
CellCount: TYPE = RECORD[total, current: LONG INTEGER];

-- CONSTANTS
defaultCollectionInterval: LONG CARDINAL = 40000B;

-- VARIABLES
nWordsAllocated: LONG CARDINAL;
SUMnWordsAllocated: LONG CARDINAL;
nObjectsCreated: LONG CARDINAL;
MapPsbiToWordsAllocated: LONG POINTER TO PSBIMap;
CollectionInterval: LONG INTEGER;
SuspensionThreshold: LONG INTEGER;

AllocatorCallbackProcForSpy: UNSPECIFIED; -- YAAAAAAAAAAHHHHRRRRRGGGGGHHHH

--PROCS

ResetNWordsAllocated: PROC;

ResetTotalNWordsAllocatedOnly: PROC;

ConsiderCollection: PROC[size: CARDINAL] =
INLINE
{psbi: PSB.PsbIndex = RTOS.GetCurrent[];
nw: LONG INTEGER ← MapPsbiToWordsAllocated.elements[psbi].current + size;
MapPsbiToWordsAllocated.elements[psbi].current ← nw;

nWordsAllocated ← nWordsAllocated + size; -- total count for all processes

IF LOOPHOLE[nWordsAllocated, LONG INTEGER] >= CollectionInterval
THEN RTRefCounts.InternalReclaim[allocationInterval,
nw > SuspensionThreshold]};

END.