[Glacier] Allow removing from an intrusive list.

This commit is contained in:
Drew Galbraith 2023-12-07 00:18:33 -08:00
parent 961389dee8
commit 66e94ac41b
1 changed files with 25 additions and 0 deletions

View File

@ -20,6 +20,8 @@ class IntrusiveList {
void PushFront(const RefPtr<T>& obj);
void PushBack(const RefPtr<T>& obj);
void Remove(const RefPtr<T>& obj);
RefPtr<T> PopFront();
RefPtr<T> PopBack();
@ -64,6 +66,29 @@ void IntrusiveList<T>::PushBack(const RefPtr<T>& obj) {
back_ = obj;
}
template <typename T>
void IntrusiveList<T>::Remove(const RefPtr<T>& 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 <typename T>
RefPtr<T> IntrusiveList<T>::PopFront() {
if (front_ == nullptr) {