summaryrefslogtreecommitdiff
path: root/include/intrusive_list_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/intrusive_list_impl.h')
-rw-r--r--include/intrusive_list_impl.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/intrusive_list_impl.h b/include/intrusive_list_impl.h
index 41fc72a1f..0efe06d2e 100644
--- a/include/intrusive_list_impl.h
+++ b/include/intrusive_list_impl.h
@@ -66,6 +66,9 @@ class INSPIRCD_INTRUSIVE_LIST_NAME
INSPIRCD_INTRUSIVE_LIST_NAME()
: listhead(NULL)
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+ , listtail(NULL)
+#endif
, listsize(0)
{
}
@@ -107,9 +110,37 @@ class INSPIRCD_INTRUSIVE_LIST_NAME
x->intrusive_list_node<T, Tag>::ptr_next = listhead;
listhead->intrusive_list_node<T, Tag>::ptr_prev = x;
}
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+ else
+ listtail = x;
+#endif
listhead = x;
}
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+ T* back() const
+ {
+ return listtail;
+ }
+
+ void push_back(T* x)
+ {
+ if (listsize++)
+ {
+ x->intrusive_list_node<T, Tag>::ptr_prev = listtail;
+ listtail->intrusive_list_node<T, Tag>::ptr_next = x;
+ }
+ else
+ listhead = x;
+ listtail = x;
+ }
+
+ void pop_back()
+ {
+ erase(listtail);
+ }
+#endif
+
void erase(const iterator& it)
{
erase(*it);
@@ -119,11 +150,18 @@ class INSPIRCD_INTRUSIVE_LIST_NAME
{
if (listhead == x)
listhead = x->intrusive_list_node<T, Tag>::ptr_next;
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+ if (listtail == x)
+ listtail = x->intrusive_list_node<T, Tag>::ptr_prev;
+#endif
x->intrusive_list_node<T, Tag>::unlink();
listsize--;
}
private:
T* listhead;
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+ T* listtail;
+#endif
size_t listsize;
};