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