ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ResourceCleanup Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ResourceCleanup()

ResourceCleanup::ResourceCleanup ( )
default

◆ ~ResourceCleanup()

ResourceCleanup::~ResourceCleanup ( )
inline

Definition at line 56 of file ResourceCleanup.hpp.

Member Function Documentation

◆ empty()

auto ResourceCleanup::empty ( ) const
inline

Definition at line 143 of file ResourceCleanup.hpp.

◆ push()

template<typename Attorney , typename Container >
void ResourceCleanup::push ( std::shared_ptr< Container > const &  resource)
inline

Register a resource for cleanup.

Internally, a weak pointer is created and stored in a callback.

Template Parameters
AttorneySpecialization of ResourceCleanup::Attorney that wraps the class Container deallocator.
ContainerClass that manages resources.

Definition at line 153 of file ResourceCleanup.hpp.

Referenced by GpuParticleData::Storage::make_shared().

◆ size()

auto ResourceCleanup::size ( ) const
inline

Definition at line 142 of file ResourceCleanup.hpp.


The documentation for this class was generated from the following file: