Tervel  1.0.0
A collection of wait-free containers and algorithms.
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
tervel::util::memory::rc::PoolElement Class Reference

This class is used to hold the memory management information (Header) and a descriptor object. More...

#include <pool_element.h>

Classes

struct  Header
 All the member variables of PoolElement are stored in a struct so that the left over memory for cache padding can be easily calculated. More...
 

Public Member Functions

 PoolElement (PoolElement *next=nullptr)
 
 ~PoolElement ()
 
Descriptordescriptor ()
 Returns a pointer to the associated descriptor of this element. More...
 
Headerheader ()
 A reference to the header which houses all the special info. More...
 
PoolElementnext ()
 Helper method for getting the next pointer. More...
 
void next (PoolElement *next)
 Helper method for setting the next pointer. More...
 
template<typename DescrType , typename... Args >
void init_descriptor (Args &&...args)
 Constructs a descriptor of the given type within this pool element. More...
 
void cleanup_descriptor ()
 Should be called by the owner of this element when the descriptor in this element is no longer needed, and it is safe to destroy it. More...
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (PoolElement)
 

Private Attributes

char padding_ [CACHE_LINE_SIZE-sizeof(Header)]
 
Header header_
 

Detailed Description

This class is used to hold the memory management information (Header) and a descriptor object.

It is important to sepearte them to prevent the case where a thread attempts to dereference an object while its type id is being changed.

Constructor & Destructor Documentation

tervel::util::memory::rc::PoolElement::PoolElement ( PoolElement next = nullptr)
inlineexplicit
tervel::util::memory::rc::PoolElement::~PoolElement ( )
inline

Member Function Documentation

void tervel::util::memory::rc::PoolElement::cleanup_descriptor ( )
inline

Should be called by the owner of this element when the descriptor in this element is no longer needed, and it is safe to destroy it.

Simply calls the destructor on the internal descriptor.

Descriptor* tervel::util::memory::rc::PoolElement::descriptor ( )
inline

Returns a pointer to the associated descriptor of this element.

This pointer may or may not reference a constructed object.

Returns a pointer to the associated descriptor of this element. This pointer may or may not reference a constructed object.

TODO(carlos) add const versions of these accessors

Returns
a pointer a descriptor type
tervel::util::memory::rc::PoolElement::DISALLOW_COPY_AND_ASSIGN ( PoolElement  )
private
Header& tervel::util::memory::rc::PoolElement::header ( )
inline

A reference to the header which houses all the special info.

A reference to the header which houses all the special info

Returns
A reference to the header which houses all the
template<typename DescrType , typename... Args >
void tervel::util::memory::rc::PoolElement::init_descriptor ( Args &&...  args)

Constructs a descriptor of the given type within this pool element.

Caller must be careful that there's not another descriptor already in use in this element, or memory will be stomped and resources might leak.

Call cleanup_descriptor() to call the descriptor's destructor when done with it.

PoolElement* tervel::util::memory::rc::PoolElement::next ( )
inline

Helper method for getting the next pointer.

void tervel::util::memory::rc::PoolElement::next ( PoolElement next)
inline

Helper method for setting the next pointer.

Member Data Documentation

Header tervel::util::memory::rc::PoolElement::header_
private
char tervel::util::memory::rc::PoolElement::padding_[CACHE_LINE_SIZE-sizeof(Header)]
private

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