Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IntrusiveList lifetime documentation a little clearer. #13525

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/lib/support/IntrusiveList.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ class IntrusiveListBase
// \------------------------------------------/
//
IntrusiveListBase() : mNode(&mNode, &mNode) {}
~IntrusiveListBase() { mNode.Remove(); /* clear mNode such that the destructor checking mNode.IsInList doesn't fail */ }
~IntrusiveListBase()
{
VerifyOrDie(Empty());
/* clear mNode such that the destructor checking mNode.IsInList doesn't fail */
mNode.Remove();
}

ConstIteratorBase begin() const { return ConstIteratorBase(mNode.mNext); }
ConstIteratorBase end() const { return ConstIteratorBase(&mNode); }
Expand Down Expand Up @@ -216,7 +221,7 @@ class IntrusiveListBase
IntrusiveListNodeBase mNode;
};

/// The hook convert between node object T and IntrusiveListNodeBase
/// The hook converts between node object T and IntrusiveListNodeBase
///
/// When using this hook, the node type (T) MUST inherit from IntrusiveListNodeBase.
///
Expand All @@ -235,10 +240,12 @@ class IntrusiveListBaseHook

/// A double-linked list where the data is stored together with the previous/next pointers for cache efficiency / and compactness.
///
/// The default hook (IntrusiveListBaseHook<T>) requires T inherit from IntrusiveListNodeBase.
/// The default hook (IntrusiveListBaseHook<T>) requires T to inherit from IntrusiveListNodeBase.
///
/// Consumers must ensure that the IntrusiveListNodeBase object associated with
/// a node is removed from any list it might belong to before it is destroyed.
///
/// IntrusiveListNodeBase object associated with a node is assumed to be longer than the list they belong to. A list is effcively a
/// single node into / a chain of other nodes referenced by pointers.
/// Consumers must ensure that a list is empty before it is destroyed.
///
/// A node may only belong to a single list. The code will assert (via VerifyOrDie) on this invariant.
///
Expand All @@ -252,6 +259,8 @@ class IntrusiveListBaseHook
/// list.PushBack(&a);
/// list.PushFront(&b);
/// assert(list.Contains(&a) && list.Contains(&b) && !list.Contains(&c));
/// list.Remove(&a);
/// list.Remove(&b);
template <typename T, typename Hook = IntrusiveListBaseHook<T>>
class IntrusiveList : public IntrusiveListBase
{
Expand Down