diff --git a/lib/glacier/container/intrusive_list.h b/lib/glacier/container/intrusive_list.h index 8957a32..aef7b83 100644 --- a/lib/glacier/container/intrusive_list.h +++ b/lib/glacier/container/intrusive_list.h @@ -20,6 +20,8 @@ class IntrusiveList { void PushFront(const RefPtr& obj); void PushBack(const RefPtr& obj); + void Remove(const RefPtr& obj); + RefPtr PopFront(); RefPtr PopBack(); @@ -64,6 +66,29 @@ void IntrusiveList::PushBack(const RefPtr& obj) { back_ = obj; } +template +void IntrusiveList::Remove(const RefPtr& obj) { + if (!obj) { + return; + } + if (front_ == obj) { + front_ = obj->next_; + } + if (back_ == obj) { + back_ = obj->prev_; + } + if (obj->prev_) { + obj->prev_->next_ = obj->next_; + } + if (obj->next_) { + obj->next_->prev_ = obj->prev_; + } + + obj->prev_ = nullptr; + obj->next_ = nullptr; + size_--; +} + template RefPtr IntrusiveList::PopFront() { if (front_ == nullptr) {