Fix stack overflow in debug builds in intrusive list dtor
When destroying large intrusive lists use iteration instead of recursion.
This commit is contained in:
parent
b958847850
commit
97a3d550c2
1 changed files with 19 additions and 1 deletions
|
|
@ -20,13 +20,31 @@ namespace detail
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class intrusive_list_node
|
class intrusive_list_node
|
||||||
{
|
{
|
||||||
std::unique_ptr<T> next_;
|
public:
|
||||||
|
intrusive_list_node() = default;
|
||||||
|
|
||||||
|
intrusive_list_node(intrusive_list_node&&) = default;
|
||||||
|
intrusive_list_node& operator=(intrusive_list_node&&) = default;
|
||||||
|
|
||||||
|
~intrusive_list_node() noexcept
|
||||||
|
{
|
||||||
|
// Free iteratively to avoid stack overflow in debug builds.
|
||||||
|
auto next = next_.release();
|
||||||
|
while (next)
|
||||||
|
{
|
||||||
|
std::unique_ptr<T> cur(next);
|
||||||
|
next = cur->next_.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
void do_on_insert(const T& parent) noexcept
|
void do_on_insert(const T& parent) noexcept
|
||||||
{
|
{
|
||||||
static_cast<T&>(*this).on_insert(parent);
|
static_cast<T&>(*this).on_insert(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<T> next_;
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
friend struct intrusive_list_access;
|
friend struct intrusive_list_access;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue