Finalization: CEDAR DEFINITIONS ~ BEGIN Handle: TYPE ~ REF FinalizableObject; FinalizableObject: TYPE; FinalizationQueue: TYPE ~ REF FinalizationQueueRep; FinalizationQueueRep: TYPE; FinalizationState: TYPE ~ MACHINE DEPENDENT { enabled(0), -- waiting for all REFs to disappear onFQ(1), -- on a finalization queue disabled(2), -- none of the above error(CARDINAL.LAST) }; EnableFinalization: PROC [object: REF, fq: FinalizationQueue] RETURNS [handle: Handle]; DisableFinalization: PROC [handle: Handle] RETURNS [oldState: FinalizationState]; ReenableFinalization: PROC [handle: Handle, fq: FinalizationQueue] RETURNS [oldState: FinalizationState]; GetFinalizationState: PROC [handle: Handle] RETURNS [state: FinalizationState]; HandleToObject: PROC [handle: Handle] RETURNS [object: REF]; NewFQ: PROC RETURNS [FinalizationQueue]; FQNext: PROC [fq: FinalizationQueue] RETURNS[handle: Handle]; FQNextNoAbort: PROC [fq: FinalizationQueue] RETURNS[handle: Handle ¬ NIL]; FQEmpty: PROC [fq: FinalizationQueue] RETURNS[BOOL]; END.  Finalization.mesa Copyright Σ 1987, 1991 by Xerox Corporation. All rights reserved. Weiser, March 6, 1989 3:47:28 pm PST Demers, March 28, 1989 11:34:26 am PST Willie-s, August 6, 1991 1:13 pm PDT Types A handle is a "disguised" REF to an object. It can be converted to an ordinary REF using HandleToObject, below. An object is guaranteed not to be garbage collected while there exist handles to it. A handle may be in one of three states: enabled, onFQ, or disabled. When in the enabled or onFQ state, a handle has a FinalizationQueue associated with it. - A handle in the enabled state is awaiting finalization. It will remain in the enabled state until there are no remaining undisguised REFs or non-enabled handles referring to its object; the system will then put the handle on its associated FinalizationQueue and change its state to onFQ. - A handle in the onFQ state is on a FinalizationQueue. It will remain there until removed, either explicitly using FQNext, or implicitly by DisableFinalization or ReenableFinalization. - A handle in the disabled state is neither awaiting finalization nor on a FinalizationQueue. Such a handle can still be converted to a REF (using HandleToObject), and it prevents the associated object from being garbage collected or finalized (even if there is some other handle in the enabled state). Finalization Control Register object for finalization, returning a handle in enabled state. Disable finalization for handle, returning its previous finalization state. If handle was on a finalization queue, this removes it from the queue. Reenable finalization for handle, returning its previous finalization state . If handle was on a finalization queue, this removes it from the queue. Return the finalization state of handle. The state is computed atomically, but it is subject to change; e.g. it can change spontaneously from enabled to onFQ, and other transitions are possible as a result of calls to DisableFinalization, ReenableFinalization, or FQNext. Take a Handle and return the associated object. Finalization Queue Manipulation Return a new FinalizationQueue. Wait (with ABORTs enabled) for fq to be non-empty, then dequeue and return the first entry. Equivalent to FQNext with a catch phrase for ABORTED that just returns NIL. Test whether fq is empty. ΚΝ•NewlineDelimiter –(cedarcode) style™codešœ™Kšœ Οeœ7™BKšœ$™$K™&K™$K™—K˜šΡbln œΟkœŸ œŸ˜'K˜head™KšœŸœŸœ˜%šœŸœ˜K™—KšœŸœŸœ˜3šœŸœ˜K˜—šœŸœŸœŸ œ˜-Kšœ Οc$˜0Kšœ  ˜#Kšœ  ˜!KšœŸœŸœ˜K˜K™—™pK™—™TK™—š œ'œœœœœ<™œKš œœ8œ<œ‚œ™’Kšœœ€™ΊKšœœ†œ™―——™šΟnœŸœ ŸœŸœ˜WKšœ œ)œ™FK™—š‘œŸœŸœ˜QKšœœ,™KKšœF™FK˜—š‘œŸœ)Ÿœ˜iKšœœ-™MKšœF™F—K˜š‘œŸœŸœ˜OKšœ œhœœs™‘K˜—š‘œŸœŸœ Ÿœ˜