Finalize: 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) }; IsHandle: PROC [x: REF] RETURNS [BOOL]; NarrowHandle: PROC [x: REF] RETURNS [Handle]; EnableFinalization: PROC [object: REF, fq: FinalizationQueue, clientData: REF ¬ NIL] 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]; GetClientData: PROC [handle: Handle] RETURNS [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. Ψ Finalize.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 Christian Jacobi, July 20, 1992 11:14 am 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). Like ISTYPE[x, Handle] Like NARROW[x, Handle] Finalization Control Register object for finalization, returning a handle in enabled state. ClientData is stored for the benefit of the caller. 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. Returns client client data associated with handle. 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. Κ0•NewlineDelimiter –(cedarcode) style™code™Kšœ Οeœ7™BKšœ$™$K™&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œŸœŸœŸœŸœ˜'K™K™—š‘ œŸœŸœŸœ ˜-K™K™—™š ‘œŸœ Ÿœ%ŸœŸœŸœ˜nKšœ œ)œ<™{K™—š‘œŸœŸœ˜QKšœœ,™KKšœF™FK˜—š‘œŸœ)Ÿœ˜iKšœœ-™MKšœF™F—K˜š‘œŸœŸœ˜OKšœ œhœœs™‘K˜—š‘œŸœŸœ Ÿœ˜