1#ifndef XRPL_BASICS_INTRUSIVEREFCOUNTS_H_INCLUDED
2#define XRPL_BASICS_INTRUSIVEREFCOUNTS_H_INCLUDED
4#include <xrpl/beast/utility/instrumentation.h>
260 "xrpl::IntrusiveRefCounts::releaseStrongRef : previous ref "
264 if (prevVal.strong == 1)
266 if (prevVal.weak == 0)
285 "xrpl::IntrusiveRefCounts::releaseStrongRef : not in partial "
316 (!prevVal.partialDestroyStartedBit),
317 "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not in "
320 auto nextIntVal = prevIntVal + delta;
322 if (prevVal.strong == 1)
324 if (prevVal.weak == 0)
339 "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not "
340 "started partial destroy");
351 if (prev.weak == 1 && prev.strong == 0)
353 if (!prev.partialDestroyStartedBit)
362 if (!prev.partialDestroyFinishedBit)
411 "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : count must be zero");
415 "xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : valid tag");
430 "xrpl::IntrusiveRefCounts::RefCountPair(FieldType) : inputs inside "
441 "xrpl::IntrusiveRefCounts::RefCountPair(CountType, CountType) : "
442 "inputs inside range");
450 "xrpl::IntrusiveRefCounts::RefCountPair::combinedValue : inputs "
468 "xrpl::partialDestructorFinished : not a weak ref");
474 self.refCounts.notify_one();
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
ReleaseStrongRefAction
Action to perform when releasing a strong pointer.
ReleaseWeakRefAction
Action to perform when releasing a weak pointer.
Unpack the count and tag fields from the packed atomic integer form.
FieldType combinedValue() const noexcept
Convert back to the packed integer form.
static constexpr CountType checkWeakMaxValue
static constexpr CountType maxStrongValue
RefCountPair(FieldType v) noexcept
FieldType partialDestroyStartedBit
The partialDestroyStartedBit is set to on when the partial destroy function is started.
static constexpr CountType checkStrongMaxValue
Put an extra margin to detect when running up against limits.
FieldType partialDestroyFinishedBit
The partialDestroyFinishedBit is set to on when the partial destroy function has finished.
static constexpr CountType maxWeakValue
Implement the strong count, weak count, and bit flags for an intrusive pointer.
bool checkoutStrongRefFromWeak() const noexcept
static constexpr FieldType strongDelta
Amount to change the strong count when adding or releasing a reference.
static constexpr FieldType weakMask
Mask that will zero out everything except the weak count.
static constexpr FieldType tagMask
Mask that will zero out all the count bits and leave the tag bits unchanged.
ReleaseStrongRefAction addWeakReleaseStrongRef() const
void addWeakRef() const noexcept
static constexpr FieldType one
static constexpr size_t StrongCountNumBits
bool expired() const noexcept
friend void partialDestructorFinished(T **o)
virtual ~IntrusiveRefCounts() noexcept
std::size_t use_count() const noexcept
static constexpr FieldType partialDestroyFinishedMask
Flag that is set when the partialDestroy function has finished running.
static constexpr FieldType weakDelta
Amount to change the weak count when adding or releasing a reference.
static constexpr FieldType valueMask
Mask that will zero out the tag bits and leave the count bits unchanged.
ReleaseWeakRefAction releaseWeakRef() const
static constexpr FieldType strongMask
Mask that will zero out everything except the strong count.
ReleaseStrongRefAction releaseStrongRef() const
void addStrongRef() const noexcept
static constexpr size_t FieldTypeBits
static constexpr size_t WeakCountNumBits
static constexpr FieldType partialDestroyStartedMask
Flag that is set when the partialDestroy function has started running (or is about to start running).
std::atomic< FieldType > refCounts
refCounts consists of four fields that are treated atomically: