cycle_ptr
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
cycle_ptr::detail::base_control Class Referenceabstract

Base class for all control blocks. More...

#include <base_control.h>

Inheritance diagram for cycle_ptr::detail::base_control:
Inheritance graph
[legend]
Collaboration diagram for cycle_ptr::detail::base_control:
Collaboration graph
[legend]

Classes

class  publisher
 Address range publisher. More...
 

Public Member Functions

auto expired () const noexcept -> bool
 Test if the object managed by this control is expired.
 
auto weak_acquire () noexcept -> bool
 Used by weak to strong reference promotion. More...
 
auto acquire_no_red () noexcept -> void
 Acquire reference. More...
 
auto acquire () noexcept -> void
 Acquire reference. More...
 
auto release (bool skip_gc=false) noexcept -> void
 Release reference counter. More...
 
auto gc () noexcept -> void
 Run GC.
 
auto push_back (vertex &v) noexcept -> void
 Register a vertex.
 
auto erase (vertex &v) noexcept -> void
 Deregister a vertex.
 
virtual auto is_unowned () const noexcept -> bool
 Test if this control block represents an unowned object.
 

Static Public Member Functions

static auto unowned_control () -> intrusive_ptr< base_control >
 Create a control block that represents no ownership.
 
static auto publisher_lookup (void *addr, std::size_t len) -> intrusive_ptr< base_control >
 Implements publisher lookup based on address range.
 

Public Attributes

bool under_construction = true
 This variable indicates the managed object is under construction. More...
 

Protected Member Functions

 base_control ()
 Default constructor allocates a new generation.
 
 base_control (intrusive_ptr< generation > g) noexcept
 Constructor to use a specific generation.
 
 ~base_control () noexcept
 Destructor.
 

Friends

class generation
 
class vertex
 
template<typename >
class cycle_ptr::cycle_allocator
 
auto intrusive_ptr_add_ref (base_control *bc) noexcept -> void
 Increment reference counter. More...
 
auto intrusive_ptr_release (base_control *bc) noexcept -> void
 Decrement reference counter. More...
 

Detailed Description

Base class for all control blocks.

Contains all variables required for the algorithm to function.

Member Function Documentation

◆ acquire()

auto cycle_ptr::detail::base_control::acquire ( ) -> void
noexcept

Acquire reference.

Increments the reference counter.

May only be called on reachable instances of this.

◆ acquire_no_red()

auto cycle_ptr::detail::base_control::acquire_no_red ( ) -> void
inlinenoexcept

Acquire reference.

May only be called when it is certain there won't be red promotion involved (meaning, it's certain that the reference counter is greater than zero).

Faster than acquire().

◆ release()

auto cycle_ptr::detail::base_control::release ( bool  skip_gc = false) -> void
inlinenoexcept

Release reference counter.

Reference counter is decremented by one. If the reference counter drops to zero, a GC invocation will be performed, unless skip_gc is set.

Parameters
skip_gcFlag to suppress GC invocation. May only be set to true if caller can guarantee that this is live.

◆ weak_acquire()

auto cycle_ptr::detail::base_control::weak_acquire ( ) -> bool
noexcept

Used by weak to strong reference promotion.

Returns
True if promotion succeeded, false otherwise.

Friends And Related Function Documentation

◆ intrusive_ptr_add_ref

auto intrusive_ptr_add_ref ( base_control bc) -> void
friend

Increment reference counter.

Used by intrusive_ptr.

◆ intrusive_ptr_release

auto intrusive_ptr_release ( base_control bc) -> void
friend

Decrement reference counter.

Used by intrusive_ptr. Destroys this if the last reference goes away.

Member Data Documentation

◆ under_construction

bool cycle_ptr::detail::base_control::under_construction = true

This variable indicates the managed object is under construction.

It is used to prevent base_control::shared_from_this from handing out references until construction has completed.

If a pointer was handed out before, we would get into a difficult scenario where the constructor of an object could publish itself and then fail its construction later. At which point we would have the difficult question of how to manage a dangling pointer.

By preventing this, we prevent failed constructors from accidentally publishing an uninitialized pointer.


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