rippled
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
xrpl::SHAMapLeafNode Class Referenceabstract

#include <SHAMapLeafNode.h>

Inheritance diagram for xrpl::SHAMapLeafNode:
Inheritance graph
[legend]
Collaboration diagram for xrpl::SHAMapLeafNode:
Collaboration graph
[legend]

Public Member Functions

 SHAMapLeafNode (SHAMapLeafNode const &)=delete
 
SHAMapLeafNodeoperator= (SHAMapLeafNode const &)=delete
 
bool isLeaf () const final override
 Determines if this is a leaf node.
 
bool isInner () const final override
 Determines if this is an inner node.
 
void invariants (bool is_root=false) const final override
 
boost::intrusive_ptr< SHAMapItem const > const & peekItem () const
 
bool setItem (boost::intrusive_ptr< SHAMapItem const > i)
 Set the item that this node points to and update the node's hash.
 
std::string getString (SHAMapNodeID const &) const final override
 
virtual void partialDestructor ()
 
std::uint32_t cowid () const
 Returns the SHAMap that owns this node.
 
void unshare ()
 If this node is shared with another map, mark it as no longer shared.
 
virtual intr_ptr::SharedPtr< SHAMapTreeNodeclone (std::uint32_t cowid) const =0
 Make a copy of this node, setting the owner.
 
virtual void updateHash ()=0
 Recalculate the hash of this node.
 
SHAMapHash const & getHash () const
 Return the hash of this node.
 
virtual SHAMapNodeType getType () const =0
 Determines the type of node.
 
virtual void serializeForWire (Serializer &) const =0
 Serialize the node in a format appropriate for sending over the wire.
 
virtual void serializeWithPrefix (Serializer &) const =0
 Serialize the node in a format appropriate for hashing.
 
void addStrongRef () const noexcept
 
void addWeakRef () const noexcept
 
ReleaseStrongRefAction releaseStrongRef () const
 
ReleaseStrongRefAction addWeakReleaseStrongRef () const
 
ReleaseWeakRefAction releaseWeakRef () const
 
bool checkoutStrongRefFromWeak () const noexcept
 
bool expired () const noexcept
 
std::size_t use_count () const noexcept
 

Static Public Member Functions

static intr_ptr::SharedPtr< SHAMapTreeNodemakeFromPrefix (Slice rawNode, SHAMapHash const &hash)
 
static intr_ptr::SharedPtr< SHAMapTreeNodemakeFromWire (Slice rawNode)
 

Protected Member Functions

 SHAMapLeafNode (boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
 
 SHAMapLeafNode (boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid, SHAMapHash const &hash)
 

Protected Attributes

boost::intrusive_ptr< SHAMapItem const > item_
 
SHAMapHash hash_
 
std::uint32_t cowid_
 Determines the owning SHAMap, if any.
 

Private Types

using CountType = std::uint16_t
 
using FieldType = std::uint32_t
 

Static Private Member Functions

static intr_ptr::SharedPtr< SHAMapTreeNodemakeTransaction (Slice data, SHAMapHash const &hash, bool hashValid)
 
static intr_ptr::SharedPtr< SHAMapTreeNodemakeAccountState (Slice data, SHAMapHash const &hash, bool hashValid)
 
static intr_ptr::SharedPtr< SHAMapTreeNodemakeTransactionWithMeta (Slice data, SHAMapHash const &hash, bool hashValid)
 

Private Attributes

std::atomic< FieldTyperefCounts {strongDelta}
 refCounts consists of four fields that are treated atomically:
 

Static Private Attributes

static constexpr size_t StrongCountNumBits = sizeof(CountType) * 8
 
static constexpr size_t WeakCountNumBits = StrongCountNumBits - 2
 
static constexpr size_t FieldTypeBits = sizeof(FieldType) * 8
 
static constexpr FieldType one = 1
 
static constexpr FieldType strongDelta = 1
 Amount to change the strong count when adding or releasing a reference.
 
static constexpr FieldType weakDelta = (one << StrongCountNumBits)
 Amount to change the weak count when adding or releasing a reference.
 
static constexpr FieldType partialDestroyStartedMask = (one << (FieldTypeBits - 1))
 Flag that is set when the partialDestroy function has started running (or is about to start running).
 
static constexpr FieldType partialDestroyFinishedMask = (one << (FieldTypeBits - 2))
 Flag that is set when the partialDestroy function has finished running.
 
static constexpr FieldType tagMask = partialDestroyStartedMask | partialDestroyFinishedMask
 Mask that will zero out all the count bits and leave the tag bits unchanged.
 
static constexpr FieldType valueMask = ~tagMask
 Mask that will zero out the tag bits and leave the count bits unchanged.
 
static constexpr FieldType strongMask = ((one << StrongCountNumBits) - 1) & valueMask
 Mask that will zero out everything except the strong count.
 
static constexpr FieldType weakMask = (((one << WeakCountNumBits) - 1) << StrongCountNumBits) & valueMask
 Mask that will zero out everything except the weak count.
 

Detailed Description

Definition at line 10 of file SHAMapLeafNode.h.

Member Typedef Documentation

◆ CountType

Definition at line 100 of file IntrusiveRefCounts.h.

◆ FieldType

Definition at line 103 of file IntrusiveRefCounts.h.

Constructor & Destructor Documentation

◆ SHAMapLeafNode() [1/3]

xrpl::SHAMapLeafNode::SHAMapLeafNode ( boost::intrusive_ptr< SHAMapItem const >  item,
std::uint32_t  cowid 
)
protected

Definition at line 5 of file SHAMapLeafNode.cpp.

◆ SHAMapLeafNode() [2/3]

xrpl::SHAMapLeafNode::SHAMapLeafNode ( boost::intrusive_ptr< SHAMapItem const >  item,
std::uint32_t  cowid,
SHAMapHash const &  hash 
)
protected

Definition at line 14 of file SHAMapLeafNode.cpp.

◆ SHAMapLeafNode() [3/3]

xrpl::SHAMapLeafNode::SHAMapLeafNode ( SHAMapLeafNode const &  )
delete

Member Function Documentation

◆ operator=()

SHAMapLeafNode & xrpl::SHAMapLeafNode::operator= ( SHAMapLeafNode const &  )
delete

◆ isLeaf()

bool xrpl::SHAMapLeafNode::isLeaf ( ) const
finaloverridevirtual

Determines if this is a leaf node.

Implements xrpl::SHAMapTreeNode.

Definition at line 25 of file SHAMapLeafNode.h.

◆ isInner()

bool xrpl::SHAMapLeafNode::isInner ( ) const
finaloverridevirtual

Determines if this is an inner node.

Implements xrpl::SHAMapTreeNode.

Definition at line 31 of file SHAMapLeafNode.h.

◆ invariants()

void xrpl::SHAMapLeafNode::invariants ( bool  is_root = false) const
finaloverridevirtual

Implements xrpl::SHAMapTreeNode.

Definition at line 69 of file SHAMapLeafNode.cpp.

◆ peekItem()

boost::intrusive_ptr< SHAMapItem const > const & xrpl::SHAMapLeafNode::peekItem ( ) const

Definition at line 25 of file SHAMapLeafNode.cpp.

◆ setItem()

bool xrpl::SHAMapLeafNode::setItem ( boost::intrusive_ptr< SHAMapItem const >  i)

Set the item that this node points to and update the node's hash.

Parameters
ithe new item
Returns
false if the change was, effectively, a noop (that is, if the hash was unchanged); true otherwise.

Definition at line 31 of file SHAMapLeafNode.cpp.

◆ getString()

std::string xrpl::SHAMapLeafNode::getString ( SHAMapNodeID const &  id) const
finaloverridevirtual

Reimplemented from xrpl::SHAMapTreeNode.

Definition at line 44 of file SHAMapLeafNode.cpp.

◆ partialDestructor()

virtual void xrpl::SHAMapTreeNode::partialDestructor ( )
virtualinherited

Reimplemented in xrpl::SHAMapInnerNode.

Definition at line 68 of file SHAMapTreeNode.h.

◆ updateHash()

virtual void xrpl::SHAMapTreeNode::updateHash ( )
pure virtualinherited

◆ getHash()

SHAMapHash const & xrpl::SHAMapTreeNode::getHash ( ) const
inherited

Return the hash of this node.

Definition at line 121 of file SHAMapTreeNode.h.

◆ getType()

virtual SHAMapNodeType xrpl::SHAMapTreeNode::getType ( ) const
pure virtualinherited

◆ serializeForWire()

virtual void xrpl::SHAMapTreeNode::serializeForWire ( Serializer ) const
pure virtualinherited

Serialize the node in a format appropriate for sending over the wire.

Implemented in xrpl::SHAMapInnerNode, xrpl::SHAMapAccountStateLeafNode, xrpl::SHAMapTxLeafNode, and xrpl::SHAMapTxPlusMetaLeafNode.

◆ serializeWithPrefix()

virtual void xrpl::SHAMapTreeNode::serializeWithPrefix ( Serializer ) const
pure virtualinherited

Serialize the node in a format appropriate for hashing.

Implemented in xrpl::SHAMapInnerNode, xrpl::SHAMapAccountStateLeafNode, xrpl::SHAMapTxLeafNode, and xrpl::SHAMapTxPlusMetaLeafNode.

◆ makeFromPrefix()

intr_ptr::SharedPtr< SHAMapTreeNode > xrpl::SHAMapTreeNode::makeFromPrefix ( Slice  rawNode,
SHAMapHash const &  hash 
)
staticinherited

Definition at line 109 of file SHAMapTreeNode.cpp.

◆ makeFromWire()

intr_ptr::SharedPtr< SHAMapTreeNode > xrpl::SHAMapTreeNode::makeFromWire ( Slice  rawNode)
staticinherited

Definition at line 78 of file SHAMapTreeNode.cpp.

◆ makeTransaction()

intr_ptr::SharedPtr< SHAMapTreeNode > xrpl::SHAMapTreeNode::makeTransaction ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 16 of file SHAMapTreeNode.cpp.

◆ makeAccountState()

intr_ptr::SharedPtr< SHAMapTreeNode > xrpl::SHAMapTreeNode::makeAccountState ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 51 of file SHAMapTreeNode.cpp.

◆ makeTransactionWithMeta()

intr_ptr::SharedPtr< SHAMapTreeNode > xrpl::SHAMapTreeNode::makeTransactionWithMeta ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 27 of file SHAMapTreeNode.cpp.

◆ addStrongRef()

void xrpl::IntrusiveRefCounts::addStrongRef ( ) const
noexceptinherited

Definition at line 224 of file IntrusiveRefCounts.h.

◆ addWeakRef()

void xrpl::IntrusiveRefCounts::addWeakRef ( ) const
noexceptinherited

Definition at line 230 of file IntrusiveRefCounts.h.

◆ releaseStrongRef()

ReleaseStrongRefAction xrpl::IntrusiveRefCounts::releaseStrongRef ( ) const
inherited

Definition at line 236 of file IntrusiveRefCounts.h.

◆ addWeakReleaseStrongRef()

ReleaseStrongRefAction xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef ( ) const
inherited

Definition at line 284 of file IntrusiveRefCounts.h.

◆ releaseWeakRef()

ReleaseWeakRefAction xrpl::IntrusiveRefCounts::releaseWeakRef ( ) const
inherited

Definition at line 337 of file IntrusiveRefCounts.h.

◆ checkoutStrongRefFromWeak()

bool xrpl::IntrusiveRefCounts::checkoutStrongRefFromWeak ( ) const
noexceptinherited

Definition at line 364 of file IntrusiveRefCounts.h.

◆ expired()

bool xrpl::IntrusiveRefCounts::expired ( ) const
noexceptinherited

Definition at line 381 of file IntrusiveRefCounts.h.

◆ use_count()

std::size_t xrpl::IntrusiveRefCounts::use_count ( ) const
noexceptinherited

Definition at line 388 of file IntrusiveRefCounts.h.

Member Data Documentation

◆ item_

boost::intrusive_ptr<SHAMapItem const> xrpl::SHAMapLeafNode::item_
protected

Definition at line 13 of file SHAMapLeafNode.h.

◆ hash_

SHAMapHash xrpl::SHAMapTreeNode::hash_
protectedinherited

Definition at line 33 of file SHAMapTreeNode.h.

◆ cowid_

std::uint32_t xrpl::SHAMapTreeNode::cowid_
protectedinherited

Determines the owning SHAMap, if any.

Used for copy-on-write semantics.

If this value is 0, the node is not dirty and does not need to be flushed. It is eligible for sharing and may be included multiple SHAMap instances.

Definition at line 41 of file SHAMapTreeNode.h.

◆ StrongCountNumBits

constexpr size_t xrpl::IntrusiveRefCounts::StrongCountNumBits = sizeof(CountType) * 8
staticconstexprprivateinherited

Definition at line 101 of file IntrusiveRefCounts.h.

◆ WeakCountNumBits

constexpr size_t xrpl::IntrusiveRefCounts::WeakCountNumBits = StrongCountNumBits - 2
staticconstexprprivateinherited

Definition at line 102 of file IntrusiveRefCounts.h.

◆ FieldTypeBits

constexpr size_t xrpl::IntrusiveRefCounts::FieldTypeBits = sizeof(FieldType) * 8
staticconstexprprivateinherited

Definition at line 104 of file IntrusiveRefCounts.h.

◆ one

constexpr FieldType xrpl::IntrusiveRefCounts::one = 1
staticconstexprprivateinherited

Definition at line 105 of file IntrusiveRefCounts.h.

◆ refCounts

std::atomic<FieldType> xrpl::IntrusiveRefCounts::refCounts {strongDelta}
mutableprivateinherited

refCounts consists of four fields that are treated atomically:

  1. Strong count. This is a count of the number of shared pointers that hold a reference to this object. When the strong counts goes to zero, if the weak count is zero, the destructor is run. If the weak count is non-zero when the strong count goes to zero then the partialDestructor is run.
  2. Weak count. This is a count of the number of weak pointer that hold a reference to this object. When the weak count goes to zero and the strong count is also zero, then the destructor is run.
  3. Partial destroy started bit. This bit is set if the partialDestructor function has been started (or is about to be started). This is used to prevent the destructor from running concurrently with the partial destructor. This can easily happen when the last strong pointer release its reference in one thread and starts the partialDestructor, while in another thread the last weak pointer goes out of scope and starts the destructor while the partialDestructor is still running. Both a start and finished bit is needed to handle a corner-case where the last strong pointer goes out of scope, then then last weakPointer goes out of scope, but this happens before the partialDestructor bit is set. It would be possible to use a single bit if it could also be set atomically when the strong count goes to zero and the weak count is non-zero, but that would add complexity (and likely slow down common cases as well).
  4. Partial destroy finished bit. This bit is set when the partialDestructor has finished running. See (3) above for more information.

Definition at line 140 of file IntrusiveRefCounts.h.

◆ strongDelta

constexpr FieldType xrpl::IntrusiveRefCounts::strongDelta = 1
staticconstexprprivateinherited

Amount to change the strong count when adding or releasing a reference.

Note: The strong count is stored in the low StrongCountNumBits bits of refCounts

Definition at line 147 of file IntrusiveRefCounts.h.

◆ weakDelta

constexpr FieldType xrpl::IntrusiveRefCounts::weakDelta = (one << StrongCountNumBits)
staticconstexprprivateinherited

Amount to change the weak count when adding or releasing a reference.

Note: The weak count is stored in the high WeakCountNumBits bits of refCounts

Definition at line 154 of file IntrusiveRefCounts.h.

◆ partialDestroyStartedMask

constexpr FieldType xrpl::IntrusiveRefCounts::partialDestroyStartedMask = (one << (FieldTypeBits - 1))
staticconstexprprivateinherited

Flag that is set when the partialDestroy function has started running (or is about to start running).

See description of the refCounts field for a fuller description of this field.

Definition at line 162 of file IntrusiveRefCounts.h.

◆ partialDestroyFinishedMask

constexpr FieldType xrpl::IntrusiveRefCounts::partialDestroyFinishedMask = (one << (FieldTypeBits - 2))
staticconstexprprivateinherited

Flag that is set when the partialDestroy function has finished running.

See description of the refCounts field for a fuller description of this field.

Definition at line 169 of file IntrusiveRefCounts.h.

◆ tagMask

constexpr FieldType xrpl::IntrusiveRefCounts::tagMask = partialDestroyStartedMask | partialDestroyFinishedMask
staticconstexprprivateinherited

Mask that will zero out all the count bits and leave the tag bits unchanged.

Definition at line 174 of file IntrusiveRefCounts.h.

◆ valueMask

constexpr FieldType xrpl::IntrusiveRefCounts::valueMask = ~tagMask
staticconstexprprivateinherited

Mask that will zero out the tag bits and leave the count bits unchanged.

Definition at line 179 of file IntrusiveRefCounts.h.

◆ strongMask

constexpr FieldType xrpl::IntrusiveRefCounts::strongMask = ((one << StrongCountNumBits) - 1) & valueMask
staticconstexprprivateinherited

Mask that will zero out everything except the strong count.

Definition at line 183 of file IntrusiveRefCounts.h.

◆ weakMask

constexpr FieldType xrpl::IntrusiveRefCounts::weakMask = (((one << WeakCountNumBits) - 1) << StrongCountNumBits) & valueMask
staticconstexprprivateinherited

Mask that will zero out everything except the weak count.

Definition at line 187 of file IntrusiveRefCounts.h.