libfoedus-core
FOEDUS Core Library
foedus::Attachable< CONTROL_BLOCK > Class Template Reference

Attachable Resources on Shared Memory. More...

Detailed Description

template<typename CONTROL_BLOCK>
class foedus::Attachable< CONTROL_BLOCK >

Attachable Resources on Shared Memory.

Objects that live in Shared Memory
FOEDUS has several objects whose data are stored in shared memory so that all SOCs can access them. Such objects have a certain pattern for being initialized and used. Namely:
  • The master engine allocates shared memory where the entire data or at least shared part of the object are placed.
  • Either the master engine or some SOC initializes the shared data on shared memory.
  • Other SOCs attach the shared data to a local object.
  • When FOEDUS shuts down, either the master engine or some SOC uninitializes the shared data.
Control block, or a pointer to Shared Memory
The essense of these attachable objects is the control-block, the shared data of shared memory. Typically, the only data element of an attachable object is the pointer to shared memory. An attachable object can have non-shared data, and in fact many attachable objects do so, but remember that it will make copying more expensive.
Copyable/Moveable
Attachable objects should be trivally copy-able and move-able without any expensive operation because all shared data are on the shared memory. We just copy the pointer to it. This makes several things simpler and more efficient. Rather than we instantiate attachable objects on heap, we often just return/copy them on stack. This is not a mandatory requirement to be attachable, but attachable objects that require frequent instantiate/copy should place almost all data in shared memory.
Destruct/Detach
There is no destruct/detach interface for these objects. To be trivially copy-able, these objects shouldn't need an explicit destruction or detachment. If it's really needed, override the destructor.

Definition at line 58 of file attachable.hpp.

#include <attachable.hpp>

Inheritance diagram for foedus::Attachable< CONTROL_BLOCK >:
Collaboration diagram for foedus::Attachable< CONTROL_BLOCK >:

Public Member Functions

 Attachable ()
 
 Attachable (Engine *engine)
 
 Attachable (Engine *engine, CONTROL_BLOCK *control_block)
 
 Attachable (CONTROL_BLOCK *control_block)
 
virtual ~Attachable ()
 
 Attachable (const Attachable &other)
 
Attachableoperator= (const Attachable &other)
 
virtual void attach (CONTROL_BLOCK *control_block)
 Attaches to the given shared memory. More...
 
bool is_attached () const
 Returns whether the object has been already attached to some shared memory. More...
 
CONTROL_BLOCK * get_control_block () const
 
Engineget_engine () const
 
void set_engine (Engine *engine)
 

Protected Attributes

Engineengine_
 Most attachable object stores an engine pointer (local engine), so we define it here. More...
 
CONTROL_BLOCK * control_block_
 The shared data on shared memory that has been initialized in some SOC or master engine. More...
 

Constructor & Destructor Documentation

template<typename CONTROL_BLOCK>
foedus::Attachable< CONTROL_BLOCK >::Attachable ( )
inline

Definition at line 60 of file attachable.hpp.

#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
foedus::Attachable< CONTROL_BLOCK >::Attachable ( Engine engine)
inlineexplicit

Definition at line 61 of file attachable.hpp.

#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
foedus::Attachable< CONTROL_BLOCK >::Attachable ( Engine engine,
CONTROL_BLOCK *  control_block 
)
inline

Definition at line 62 of file attachable.hpp.

64  attach(control_block);
65  }
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
virtual void attach(CONTROL_BLOCK *control_block)
Attaches to the given shared memory.
Definition: attachable.hpp:91
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
foedus::Attachable< CONTROL_BLOCK >::Attachable ( CONTROL_BLOCK *  control_block)
inlineexplicit

Definition at line 66 of file attachable.hpp.

68  attach(control_block);
69  }
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
virtual void attach(CONTROL_BLOCK *control_block)
Attaches to the given shared memory.
Definition: attachable.hpp:91
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
virtual foedus::Attachable< CONTROL_BLOCK >::~Attachable ( )
inlinevirtual

Definition at line 70 of file attachable.hpp.

70 {}
template<typename CONTROL_BLOCK>
foedus::Attachable< CONTROL_BLOCK >::Attachable ( const Attachable< CONTROL_BLOCK > &  other)
inline

Definition at line 73 of file attachable.hpp.

74  : engine_(other.engine_), control_block_(other.control_block_) {}
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111

Member Function Documentation

template<typename CONTROL_BLOCK>
virtual void foedus::Attachable< CONTROL_BLOCK >::attach ( CONTROL_BLOCK *  control_block)
inlinevirtual

Attaches to the given shared memory.

Parameters
[in]control_blockpointer to shared data on shared memory
Precondition
someone has (or at least will before this object actually does something) initialized this object on the shared memory.

This method should never fail so that we can provide a trivially copy-able semantics. In many cases, this method should be just setting control_block_ as done in the default implementation below. If the object needs to set more things, override this.

Definition at line 91 of file attachable.hpp.

Referenced by foedus::Attachable< LogGleanerControlBlock >::Attachable(), and foedus::log::LogManagerPimpl::initialize_once().

91  {
92  control_block_ = control_block;
93  }
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111

Here is the caller graph for this function:

template<typename CONTROL_BLOCK>
Engine* foedus::Attachable< CONTROL_BLOCK >::get_engine ( ) const
inline

Definition at line 99 of file attachable.hpp.

Referenced by foedus::storage::sequential::SequentialAppendLogType::apply_record().

99 { return engine_; }
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107

Here is the caller graph for this function:

template<typename CONTROL_BLOCK>
bool foedus::Attachable< CONTROL_BLOCK >::is_attached ( ) const
inline

Returns whether the object has been already attached to some shared memory.

Definition at line 96 of file attachable.hpp.

96 { return control_block_; }
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
Attachable& foedus::Attachable< CONTROL_BLOCK >::operator= ( const Attachable< CONTROL_BLOCK > &  other)
inline

Definition at line 75 of file attachable.hpp.

75  {
76  engine_ = other.engine_;
77  control_block_ = other.control_block_;
78  return *this;
79  }
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
CONTROL_BLOCK * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
template<typename CONTROL_BLOCK>
void foedus::Attachable< CONTROL_BLOCK >::set_engine ( Engine engine)
inline

Definition at line 100 of file attachable.hpp.

Referenced by foedus::log::LogManagerPimpl::initialize_once().

100 { engine_ = engine; }
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107

Here is the caller graph for this function:

Member Data Documentation


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