|
rippled
|
Implement the strong count, weak count, and bit flags for an intrusive pointer. More...
#include <IntrusiveRefCounts.h>


Classes | |
| struct | RefCountPair |
| Unpack the count and tag fields from the packed atomic integer form. More... | |
Public Member Functions | |
| virtual | ~IntrusiveRefCounts () noexcept |
| 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 |
Private Types | |
| using | CountType = std::uint16_t |
| using | FieldType = std::uint32_t |
Private Attributes | |
| std::atomic< FieldType > | refCounts {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 |
| Flag that is set when the partialDestroy function has started running (or is about to start running). | |
| static constexpr FieldType | partialDestroyFinishedMask |
| Flag that is set when the partialDestroy function has finished running. | |
| static constexpr FieldType | tagMask |
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 |
| Mask that will zero out everything except the strong count. | |
| static constexpr FieldType | weakMask |
| Mask that will zero out everything except the weak count. | |
Friends | |
| template<class T > | |
| void | partialDestructorFinished (T **o) |
Implement the strong count, weak count, and bit flags for an intrusive pointer.
A class can satisfy the requirements of a ripple::IntrusivePointer by inheriting from this class.
Definition at line 40 of file IntrusiveRefCounts.h.
|
private |
Definition at line 101 of file IntrusiveRefCounts.h.
|
private |
Definition at line 104 of file IntrusiveRefCounts.h.
|
virtualnoexcept |
Definition at line 405 of file IntrusiveRefCounts.h.
|
noexcept |
Definition at line 232 of file IntrusiveRefCounts.h.
|
noexcept |
Definition at line 238 of file IntrusiveRefCounts.h.
| ReleaseStrongRefAction ripple::IntrusiveRefCounts::releaseStrongRef | ( | ) | const |
Definition at line 244 of file IntrusiveRefCounts.h.
| ReleaseStrongRefAction ripple::IntrusiveRefCounts::addWeakReleaseStrongRef | ( | ) | const |
Definition at line 293 of file IntrusiveRefCounts.h.
| ReleaseWeakRefAction ripple::IntrusiveRefCounts::releaseWeakRef | ( | ) | const |
Definition at line 347 of file IntrusiveRefCounts.h.
|
noexcept |
Definition at line 374 of file IntrusiveRefCounts.h.
|
noexcept |
Definition at line 392 of file IntrusiveRefCounts.h.
|
noexcept |
Definition at line 399 of file IntrusiveRefCounts.h.
|
friend |
Definition at line 460 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Definition at line 102 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Definition at line 103 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Definition at line 105 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Definition at line 106 of file IntrusiveRefCounts.h.
|
mutableprivate |
refCounts consists of four fields that are treated atomically:
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).partialDestructor has finished running. See (3) above for more information. Definition at line 141 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
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 148 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
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 155 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
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 163 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
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 171 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Mask that will zero out all the count bits and leave the tag bits unchanged.
Definition at line 177 of file IntrusiveRefCounts.h.
Mask that will zero out the tag bits and leave the count bits unchanged.
Definition at line 183 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Mask that will zero out everything except the strong count.
Definition at line 187 of file IntrusiveRefCounts.h.
|
staticconstexprprivate |
Mask that will zero out everything except the weak count.
Definition at line 192 of file IntrusiveRefCounts.h.