/* * DNN - Data News Network * * by Stephane Chatty and Stephane Sire * * Copyright 1993-1996 * Centre d'Etudes de la Navigation Aerienne (CENA) * * Disposable objects. * * $Id$ * $CurLog$ */ #include "Disposable.h" #include "Loop.h" bool IvlDisposable::ClassInitialized = false; IvlInitializerFor IvlDisposable::Dependance; IvlInitializerFor IvlDisposable::Initializer; IvlListOf IvlDisposable::Garbage; void IvlDisposable :: ClassInit () { if (!ClassInitialized) { ClassInitialized = true; IvlBaseMultiplexer::AddGlobalHook (&IvlDisposable::DeleteGarbage, true); } } #if 0 void IvlDisposable :: ClassClose () { IvlBaseMultiplexer::RemoveGlobalHook (&IvlDisposable::DeleteGarbage); } #endif /*? \typ{IvlDisposable} objects are objects whose deletion is called in a safe place in an asynchronous way. Instances of derived class of IvlDisposable which are to be deleted asynchronously must be allocated only dynamically with new. An instance is put into it's class garbage list (and thus deleted) by calling \fun{AsynchronousDelete} on itself. A mechanism of Lock and Unlock is also provided to prevent a deletion while in an unsafe state. Typically this class is to be used by derivation of UchChannel which can be deleted from within themselves after a call to \fun{HandleRead}. ?*/ IvlDisposable :: IvlDisposable () { } IvlDisposable :: ~IvlDisposable () { } void IvlDisposable :: Trash () { Garbage.Append (this); }; /*? Delete all the instances which are in the garbage list. ?*/ void IvlDisposable :: DeleteGarbage () { IvlDisposable* d; while (d = Garbage.RemoveFirst ()) delete d; }