ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
Queue to deallocate resources before normal program termination. More...
#include <ResourceCleanup.hpp>
Classes | |
class | Attorney |
Attorney for a resource deallocator. More... | |
Public Member Functions | |
ResourceCleanup ()=default | |
~ResourceCleanup () | |
auto | size () const |
auto | empty () const |
template<typename Attorney , typename Container > | |
void | push (std::shared_ptr< Container > const &resource) |
Register a resource for cleanup. | |
Queue to deallocate resources before normal program termination.
Some resources can only be deallocated when a static global object is still alive, for example a MPI manager, a GPU context or a file handle. This class can be registered as a callback for normal program termination; any registered resource that didn't expire will be forcefully deallocated.
To this end, the "client" class needs to implement cleanup methods that deallocate managed resources, to be called by the class destructor when the instance lifetime expires, or by an "attorney" class at normal program termination, whichever comes first. The attorney class creates a callback that is pushed in a queue that gets processed before normal program termination at the user's discretion, or when the queue itself expires, if the client class instance hasn't expired already.
Please note the cleanup methods need to be able to run twice, since the client class destructor will be called eventually, possibly after __run_exit_handlers()
is called. The attorney-client idiom is used to make the private deallocation methods accessible to the cleanup callbacks.
Definition at line 47 of file ResourceCleanup.hpp.
|
default |
|
inline |
Definition at line 56 of file ResourceCleanup.hpp.
|
inline |
Definition at line 143 of file ResourceCleanup.hpp.
|
inline |
Register a resource for cleanup.
Internally, a weak pointer is created and stored in a callback.
Attorney | Specialization of ResourceCleanup::Attorney that wraps the class Container deallocator. |
Container | Class that manages resources. |
Definition at line 153 of file ResourceCleanup.hpp.
Referenced by GpuParticleData::Storage::make_shared().
|
inline |
Definition at line 142 of file ResourceCleanup.hpp.