diff options
Diffstat (limited to 'dnn/Disposable.cc')
-rwxr-xr-x | dnn/Disposable.cc | 78 |
1 files changed, 78 insertions, 0 deletions
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<DnnBaseMultiplexer> DnnDisposable::Dependance; +CcuInitializerFor<DnnDisposable> DnnDisposable::Initializer; +CcuListOf<DnnDisposable> 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; +} |