MADNESS 0.10.1
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
madness::WorldObjectBase Struct Reference

Base class for WorldObject. More...

#include <world_object.h>

Inheritance diagram for madness::WorldObjectBase:
Inheritance graph
[legend]
Collaboration diagram for madness::WorldObjectBase:
Collaboration graph
[legend]

Public Member Functions

virtual ~WorldObjectBase ()
 
Worldget_world () const
 
Worldget_world_noexcept () const noexcept
 Get the world to which this object belongs, without risking a throw.
 
const uniqueidTid () const
 Returns the globally unique object ID.
 
bool world_is_alive () const noexcept
 Reports whether the world to which this object belongs still exists.
 

Protected Member Functions

 WorldObjectBase (const WorldObjectBase &other)
 Copy constructor; produces an unregistered object.
 
 WorldObjectBase (World &w)
 Construct a new WorldObjectBase.
 
Worldget_world_unchecked () const noexcept
 Unchecked access to the memoized world reference.
 
template<typename DerivedT >
void register_self (DerivedT *this_ptr)
 Registers this object with its world, making it globally addressable.
 

Private Attributes

uniqueidT objid
 Unique object ID; null until register_self() has been called.
 
Worldworld
 Memoized reference to the world to which this object belongs.
 
World::liveness_handleT world_liveness
 Reports whether world is still alive.
 

Detailed Description

Base class for WorldObject.

Holds the parts of a WorldObject that do not depend on the derived class: the unique object ID and the World the object belongs to, the latter accessible to the derived class via get_world(). Should not be used directly, but rather through WorldObject<Derived>.

Constructor & Destructor Documentation

◆ WorldObjectBase() [1/2]

madness::WorldObjectBase::WorldObjectBase ( World w)
inlineexplicitprotected

Construct a new WorldObjectBase.

Protected, should only be called from the WorldObject constructor.

Note
This does not register the object with w; the derived WorldObject must call register_self() to do that, once its own members have been initialized.
Parameters
[in]wThe world to which this object belongs.

◆ WorldObjectBase() [2/2]

madness::WorldObjectBase::WorldObjectBase ( const WorldObjectBase other)
inlineprotected

Copy constructor; produces an unregistered object.

Exists solely so that the derived WorldObject remains copy constructible (which pre-C++17 is needed to permit RVO), never to produce a usable object. The copy aliases the world of other but deliberately does not copy its ID and is not registered with the world: were the copy destroyed it would otherwise unregister other, evicting a live object from the world's ID maps.

Parameters
[in]otherThe object whose world is to be aliased.

◆ ~WorldObjectBase()

virtual madness::WorldObjectBase::~WorldObjectBase ( )
inlinevirtual

Member Function Documentation

◆ get_world()

World & madness::WorldObjectBase::get_world ( ) const
inline

Get the world to which this object belongs.

Returns
A reference to the world.
Note
The reference is memoized, hence only valid while that world is alive; this is asserted here rather than paying for a lookup of the world by its ID, since get_world() is called in hot loops.
Todo:
Promote the assertion to MADNESS_CHECK, so that the use-after-free is also caught in release builds (where MADNESS_ASSERT compiles away), once the cost of the liveness load in hot loops has been measured.

References MADNESS_ASSERT, world, and world_is_alive().

Referenced by madness::SeparatedConvolution< Q, NDIM >::combine(), madness::ScalarResultImpl< T >::gaxpy(), madness::ScalarResultImpl< T >::get(), madness::BatchTransport::on_reply(), madness::BatchTransport::on_trigger(), Foo::ping(), Foo::ping_am(), Foo::pong(), Foo::pong_am(), madness::SeparatedConvolution< Q, NDIM >::print_timer(), Array::read(), madness::WorldContainerImpl< keyT, valueT, hashfunT >::redistribute_phase2(), madness::WorldContainerImpl< keyT, valueT, hashfunT >::replicate(), madness::WorldContainerImpl< keyT, valueT, hashfunT >::replicate_on_hosts(), madness::BatchTransport::request(), madness::WorldContainerImpl< keyT, valueT, hashfunT >::reset_pmap_to_local(), madness::SeparatedConvolution< Q, NDIM >::reset_timer(), madness::WorldObject< Derived >::send_am(), madness::WorldObject< Derived >::send_task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), madness::WorldObject< Derived >::task(), TestFutureForwarding::test(), and Array::write().

◆ get_world_noexcept()

World & madness::WorldObjectBase::get_world_noexcept ( ) const
inlinenoexcept

Get the world to which this object belongs, without risking a throw.

Same as get_world(), except the memoized reference is validated with MADNESS_ASSERT_NOEXCEPT, which aborts rather than throws. Use this from destructors and other noexcept contexts, where a throwing MADNESS_ASSERT would call std::terminate and thereby discard the diagnostic.

Returns
A reference to the world.

References MADNESS_ASSERT_NOEXCEPT, world, and world_is_alive().

Referenced by madness::WorldObject< Derived >::~WorldObject().

◆ get_world_unchecked()

World & madness::WorldObjectBase::get_world_unchecked ( ) const
inlineprotectednoexcept

Unchecked access to the memoized world reference.

Warning
Does not validate that the world is still alive; only use where that has already been established (e.g. right after a world_is_alive() check).
Returns
A reference to the world.

References world.

◆ id()

const uniqueidT & madness::WorldObjectBase::id ( ) const
inline

◆ register_self()

template<typename DerivedT >
void madness::WorldObjectBase::register_self ( DerivedT this_ptr)
inlineprotected

Registers this object with its world, making it globally addressable.

Attention
Must be called by the WorldObject constructor after all of its members have been initialized: registration publishes this object to the active-message handlers running on the runtime threads, which read those members (see WorldObject::is_ready()).
Template Parameters
DerivedTThe derived class being registered.
Parameters
[in]this_ptrPointer to the derived object being registered.

References MADNESS_ASSERT, madness::nonlinear_vector_solver(), objid, madness::World::register_ptr(), and world.

Referenced by madness::WorldObject< Derived >::WorldObject().

◆ world_is_alive()

bool madness::WorldObjectBase::world_is_alive ( ) const
inlinenoexcept

Reports whether the world to which this object belongs still exists.

A WorldObject must not outlive its World, but it happens; this makes the (otherwise silent) use-after-free detectable.

Returns
True if the world of this object has not been destroyed yet.

References world_liveness.

Referenced by madness::WorldObject< Derived >::~WorldObject(), ~WorldObjectBase(), get_world(), and get_world_noexcept().

Member Data Documentation

◆ objid

uniqueidT madness::WorldObjectBase::objid
private

Unique object ID; null until register_self() has been called.

Referenced by ~WorldObjectBase(), id(), and register_self().

◆ world

World& madness::WorldObjectBase::world
private

◆ world_liveness

World::liveness_handleT madness::WorldObjectBase::world_liveness
private

Reports whether world is still alive.

Referenced by world_is_alive().


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