3#include <xrpl/beast/utility/instrumentation.h>
268 auto prevIntVal =
refCounts_.load(std::memory_order_acquire);
274 "xrpl::IntrusiveRefCounts::releaseStrongRef : previous ref "
280 if (prevVal.
weak == 0)
291 if (
refCounts_.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel))
298 "xrpl::IntrusiveRefCounts::releaseStrongRef : not in partial "
312 auto prevIntVal =
refCounts_.load(std::memory_order_acquire);
330 "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not in "
333 auto nextIntVal = prevIntVal + kDelta;
337 if (prevVal.
weak == 0)
347 if (
refCounts_.compare_exchange_weak(prevIntVal, nextIntVal, std::memory_order_acq_rel))
351 "xrpl::IntrusiveRefCounts::addWeakReleaseStrongRef : not "
352 "started partial destroy");
363 if (prev.weak == 1 && prev.strong == 0)
365 if (prev.partialDestroyStartedBit == 0u)
370 refCounts_.wait(prevIntVal, std::memory_order_acquire);
371 prevIntVal =
refCounts_.load(std::memory_order_acquire);
374 if (prev.partialDestroyFinishedBit == 0u)
391 while (!
refCounts_.compare_exchange_weak(curValue, desiredValue, std::memory_order_acq_rel))
394 if (prev.strong == 0u)
419 auto v =
refCounts_.load(std::memory_order_acquire);
421 (!(v &
kValueMask)),
"xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : count must be zero");
423 XRPL_ASSERT((!t || t ==
kTagMask),
"xrpl::IntrusiveRefCounts::~IntrusiveRefCounts : valid tag");
437 "xrpl::IntrusiveRefCounts::RefCountPair(FieldType) : inputs inside "
448 "xrpl::IntrusiveRefCounts::RefCountPair(CountType, CountType) : "
449 "inputs inside range");
457 "xrpl::IntrusiveRefCounts::RefCountPair::combinedValue : inputs "
474 "xrpl::partialDestructorFinished : not a weak ref");
480 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.
RefCountPair(FieldType v) noexcept
static constexpr CountType kMaxStrongValue
FieldType partialDestroyStartedBit
The partialDestroyStartedBit is set to on when the partial destroy function is started.
static constexpr CountType kCheckStrongMaxValue
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 kMaxWeakValue
static constexpr CountType kCheckWeakMaxValue
Implement the strong count, weak count, and bit flags for an intrusive pointer.
bool checkoutStrongRefFromWeak() const noexcept
static constexpr FieldType kPartialDestroyFinishedMask
Flag that is set when the partialDestroy function has finished running.
static constexpr FieldType kWeakMask
Mask that will zero out everything except the weak count.
static constexpr size_t kWeakCountNumBits
ReleaseStrongRefAction addWeakReleaseStrongRef() const
static constexpr FieldType kTagMask
Mask that will zero out all the count bits and leave the tag bits unchanged.
void addWeakRef() const noexcept
std::atomic< FieldType > refCounts_
refCounts consists of four fields that are treated atomically:
static constexpr FieldType kStrongDelta
Amount to change the strong count when adding or releasing a reference.
bool expired() const noexcept
static constexpr FieldType kStrongMask
Mask that will zero out everything except the strong count.
friend void partialDestructorFinished(T **o)
static constexpr size_t kFieldTypeBits
virtual ~IntrusiveRefCounts() noexcept
static constexpr FieldType kWeakDelta
Amount to change the weak count when adding or releasing a reference.
static constexpr FieldType kValueMask
Mask that will zero out the tag bits and leave the count bits unchanged.
ReleaseWeakRefAction releaseWeakRef() const
ReleaseStrongRefAction releaseStrongRef() const
void addStrongRef() const noexcept
std::size_t useCount() const noexcept
static constexpr FieldType kPartialDestroyStartedMask
Flag that is set when the partialDestroy function has started running (or is about to start running).
static constexpr FieldType kOne
static constexpr size_t kStrongCountNumBits