From bcb19dbd53973ff7efd9b2838de121d1e23430f4 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 28 Nov 2000 14:52:15 +0000 Subject: Lots of files were added around '96 --- dnn/Disposable.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 dnn/Disposable.cc (limited to 'dnn/Disposable.cc') diff --git a/dnn/Disposable.cc b/dnn/Disposable.cc new file mode 100755 index 0000000..4e8a03a --- /dev/null +++ b/dnn/Disposable.cc @@ -0,0 +1,78 @@ +/* + * 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 DnnDisposable::ClassInitialized = false; +CcuInitializerFor DnnDisposable::Dependance; +CcuInitializerFor DnnDisposable::Initializer; +CcuListOf DnnDisposable::Garbage; + +void +DnnDisposable :: ClassInit () +{ + if (!ClassInitialized) { + ClassInitialized = true; + DnnBaseMultiplexer::AddGlobalHook (&DnnDisposable::DeleteGarbage, true); + } +} + +#if 0 +void +DnnDisposable :: ClassClose () +{ + DnnBaseMultiplexer::RemoveGlobalHook (&DnnDisposable::DeleteGarbage); +} +#endif + + +/*? +\typ{DnnDisposable} objects are objects whose deletion is called in a safe +place in an asynchronous way. +Instances of derived class of DnnDisposable 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}. +?*/ +DnnDisposable :: DnnDisposable () +{ +} + +DnnDisposable :: ~DnnDisposable () +{ +} + +void +DnnDisposable :: Trash () +{ + Garbage.Append (this); +}; + +/*? +Delete all the instances which are in the garbage list. +?*/ +void +DnnDisposable :: DeleteGarbage () +{ + DnnDisposable* d; + while (d = Garbage.RemoveFirst ()) + delete d; +} -- cgit v1.1