CountedVMImpl.mesa
Last Edited by: Taft, December 10, 1983 3:03 pm
Last Edited by: Plass, December 21, 1983 1:33 pm
DIRECTORY CountedVM, PrincOps, Process, SafeStorage, VM;
CountedVMImpl: CEDAR MONITOR
IMPORTS Process, SafeStorage, VM
EXPORTS CountedVM ~
BEGIN
Handle: TYPE ~ CountedVM.Handle;
Object: TYPE ~ CountedVM.Object;
Allocate: PUBLIC PROCEDURE [words: INT, partition: VM.VMPartition, subRange: VM.Interval, start: VM.PageNumber, alignment: VM.LogPageCount, in64K: BOOL] RETURNS [h: Handle] ~
BEGIN
count: VM.PageCount ~ MAX[words+(PrincOps.wordsPerPage-1), 0]/PrincOps.wordsPerPage;
interval: VM.Interval ~ VM.Allocate[count: count, partition: partition, subRange: subRange, start: start, alignment: alignment, in64K: in64K];
h ← NEW[Object ← [interval: interval]];
SafeStorage.EnableFinalization[h];
END;
finalizationQueue: SafeStorage.FinalizationQueue ← SafeStorage.NewFQ[];
FinalizationProcess: PROCEDURE ~
BEGIN
DO
h: Handle ← NARROW[SafeStorage.FQNext[finalizationQueue]];
TRUSTED {VM.Free[h.interval]};
h ← NIL;
ENDLOOP;
END;
SafeStorage.EstablishFinalization[Object.CODE, 0, finalizationQueue];
TRUSTED {Process.Detach[FORK FinalizationProcess]};
END.