CollectibleVMImpl.mesa
Last Edited by: Taft, December 10, 1983 3:03 pm
DIRECTORY
CollectibleVM,
Process USING [Detach],
SafeStorage USING [EnableFinalization, EstablishFinalization, FinalizationQueue, FQNext, NewFQ],
VM USING [AddressForPageNumber, Allocate, Free, Interval, LogPageCount, PageCount, PageNumber, PageNumberForAddress, PagesForWords, VMPartition, WordsForPages];
CollectibleVMImpl: CEDAR MONITOR
IMPORTS Process, SafeStorage, VM
EXPORTS CollectibleVM =
BEGIN OPEN CollectibleVM;
CollectibleVM.
New: PUBLIC PROCEDURE [count: VM.PageCount, partition: VM.VMPartition ← normalVM, subRange: VM.Interval ← [0, 0], start: VM.PageNumber ← 0, alignment: VM.LogPageCount ← 0, in64K: BOOLFALSE] RETURNS [h: Handle] =
BEGIN
interval: VM.Interval = VM.Allocate[count: count, partition: partition, subRange: subRange, start: start, alignment: alignment, in64K: in64K];
TRUSTED {h ← NEW[Object ← [DESCRIPTOR[VM.AddressForPageNumber[interval.page], VM.WordsForPages[interval.count]]]]};
SafeStorage.EnableFinalization[h];
END;
Free: PUBLIC ENTRY PROCEDURE [h: Handle] = TRUSTED
BEGIN
IF h^.BASE#NIL THEN
BEGIN
VM.Free[[page: VM.PageNumberForAddress[h^.BASE], count: VM.PagesForWords[h^.LENGTH]]];
h^ ← [DESCRIPTOR[NIL, 0]];
END;
END;
Private
finalizationQueue: SafeStorage.FinalizationQueue ← SafeStorage.NewFQ[];
FinalizationProcess: PROCEDURE =
BEGIN
DO
h: Handle ← NARROW[SafeStorage.FQNext[finalizationQueue]];
Free[h];
h ← NIL;
ENDLOOP;
END;
Initialization
SafeStorage.EstablishFinalization[Object.CODE, 0, finalizationQueue];
TRUSTED {Process.Detach[FORK FinalizationProcess]};
END.