MADNESS  0.10.1
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
madness::detail::DeferredCleanup Class Reference

Deferred cleanup of shared_ptr's. More...

#include <deferred_cleanup.h>

Collaboration diagram for madness::detail::DeferredCleanup:
Collaboration graph
[legend]

Public Types

typedef std::shared_ptr< void > void_ptr
 input pointer type More...
 

Public Member Functions

 DeferredCleanup ()
 Construct a deferred deleter object. More...
 
template<typename objT >
void add (const std::shared_ptr< objT > &obj)
 Adds item to cleanup list. More...
 
void add (const void_ptr &obj)
 Adds item to cleanup list. More...
 
bool destroy () const
 Get the current destruction mode mode. More...
 
void destroy (bool mode)
 Set the destruction mode. More...
 
void do_cleanup ()
 Deletes/frees any pointers that are in the list. More...
 

Private Types

typedef std::list< void_ptrvoid_ptr_list
 

Private Member Functions

 DeferredCleanup (const DeferredCleanup &)
 
DeferredCleanupoperator= (const DeferredCleanup &)
 

Static Private Member Functions

static std::shared_ptr< DeferredCleanupget_deferred_cleanup (const World &w)
 Access deferred cleanup object of world. More...
 

Private Attributes

void_ptr_list deferred_
 List of pointers to cleanup. More...
 
bool destroy_
 
RecursiveMutex mutex_
 Worldwide mutex. More...
 

Friends

template<typename objT >
void deferred_cleanup (World &, const std::shared_ptr< objT > &, bool)
 Defer the cleanup of a shared pointer to the end of the next fence. More...
 

Detailed Description

Deferred cleanup of shared_ptr's.

Holds dynamically allocated pointers until it is ready for cleanup.

Note
This object is considered an implementation detail and should not be used directly, instead use DeferredDeleter with a std::shared_ptr.

Member Typedef Documentation

◆ void_ptr

typedef std::shared_ptr<void> madness::detail::DeferredCleanup::void_ptr

input pointer type

◆ void_ptr_list

Constructor & Destructor Documentation

◆ DeferredCleanup() [1/2]

madness::detail::DeferredCleanup::DeferredCleanup ( const DeferredCleanup )
private

◆ DeferredCleanup() [2/2]

madness::detail::DeferredCleanup::DeferredCleanup ( )
inline

Construct a deferred deleter object.

Member Function Documentation

◆ add() [1/2]

template<typename objT >
void madness::detail::DeferredCleanup::add ( const std::shared_ptr< objT > &  obj)
inline

Adds item to cleanup list.

If destroy mode is true then the pointer is destroyed immediately. Otherwise it is stored until do_cleanup() is called.

Template Parameters
objTThe object pointer type
Parameters
objObject that is ready for destruction

References add().

◆ add() [2/2]

void madness::detail::DeferredCleanup::add ( const void_ptr obj)

Adds item to cleanup list.

If destroy mode is true then the pointer is destroyed immediately. Otherwise it is stored until do_cleanup() is called.

Parameters
objObject that is ready for destruction

References deferred_, destroy_, and mutex_.

Referenced by add().

◆ destroy() [1/2]

bool madness::detail::DeferredCleanup::destroy ( ) const

Get the current destruction mode mode.

Returns
true for immediate destruction and false for deferred destruction.

References destroy_, madness::RecursiveMutex::lock(), mutex_, and madness::RecursiveMutex::unlock().

◆ destroy() [2/2]

void madness::detail::DeferredCleanup::destroy ( bool  mode)

Set the destruction mode.

Parameters
modetrue for immediate destruction, false for deferred destruction.

References destroy_, madness::RecursiveMutex::lock(), mutex_, and madness::RecursiveMutex::unlock().

◆ do_cleanup()

void madness::detail::DeferredCleanup::do_cleanup ( )

Deletes/frees any pointers that are in the list.

References deferred_, madness::RecursiveMutex::lock(), mutex_, and madness::RecursiveMutex::unlock().

◆ get_deferred_cleanup()

std::shared_ptr< DeferredCleanup > madness::detail::DeferredCleanup::get_deferred_cleanup ( const World w)
staticprivate

Access deferred cleanup object of world.

Parameters
wThe World object that holds the DeferredCleanup object
Returns
A shared pointer to the deferred cleanup object of world w.

References w().

◆ operator=()

DeferredCleanup& madness::detail::DeferredCleanup::operator= ( const DeferredCleanup )
private

Friends And Related Function Documentation

◆ deferred_cleanup

template<typename objT >
void deferred_cleanup ( World world,
const std::shared_ptr< objT > &  p,
bool  assume_p_is_unique 
)
friend

Defer the cleanup of a shared pointer to the end of the next fence.

Call this function before destroying a shared pointer. If the shared pointer is the last reference to the object, or assume_p_is_unique is true, it is placed in the deferred deletion list. Otherwise, nothing is done with the pointer.

Member Data Documentation

◆ deferred_

void_ptr_list madness::detail::DeferredCleanup::deferred_
private

List of pointers to cleanup.

Referenced by add(), and do_cleanup().

◆ destroy_

bool madness::detail::DeferredCleanup::destroy_
private

Object destroy mode true = destroy immediate false = destroy deferred (default)

Referenced by add(), and destroy().

◆ mutex_

RecursiveMutex madness::detail::DeferredCleanup::mutex_
private

Worldwide mutex.

Referenced by add(), destroy(), and do_cleanup().


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