diff --git a/src/ds/dllist.h b/src/ds/dllist.h index cdce56c..36c669c 100644 --- a/src/ds/dllist.h +++ b/src/ds/dllist.h @@ -2,6 +2,7 @@ #include "helpers.h" #include "invalidptr.h" +#include "ptrwrap.h" #include #include @@ -10,18 +11,21 @@ namespace snmalloc { template< class T, + template typename Ptr = Pointer, class Terminator = std::nullptr_t, - void on_clear(T*) = ignore> + void on_clear(Ptr) = ignore> class DLList final { private: static_assert( - std::is_same::value, "T->prev must be a T*"); + std::is_same>::value, + "T->prev must be a Ptr"); static_assert( - std::is_same::value, "T->next must be a T*"); + std::is_same>::value, + "T->next must be a Ptr"); - T* head = Terminator(); - T* tail = Terminator(); + Ptr head = Terminator(); + Ptr tail = Terminator(); public: ~DLList() @@ -55,19 +59,19 @@ namespace snmalloc return head == Terminator(); } - SNMALLOC_FAST_PATH T* get_head() + SNMALLOC_FAST_PATH Ptr get_head() { return head; } - T* get_tail() + Ptr get_tail() { return tail; } - SNMALLOC_FAST_PATH T* pop() + SNMALLOC_FAST_PATH Ptr pop() { - T* item = head; + Ptr item = head; if (item != Terminator()) remove(item); @@ -75,9 +79,9 @@ namespace snmalloc return item; } - T* pop_tail() + Ptr pop_tail() { - T* item = tail; + Ptr item = tail; if (item != Terminator()) remove(item); @@ -85,7 +89,7 @@ namespace snmalloc return item; } - void insert(T* item) + void insert(Ptr item) { #ifndef NDEBUG debug_check_not_contains(item); @@ -105,7 +109,7 @@ namespace snmalloc #endif } - void insert_back(T* item) + void insert_back(Ptr item) { #ifndef NDEBUG debug_check_not_contains(item); @@ -125,7 +129,7 @@ namespace snmalloc #endif } - SNMALLOC_FAST_PATH void remove(T* item) + SNMALLOC_FAST_PATH void remove(Ptr item) { #ifndef NDEBUG debug_check_contains(item); @@ -156,11 +160,11 @@ namespace snmalloc } } - void debug_check_contains(T* item) + void debug_check_contains(Ptr item) { #ifndef NDEBUG debug_check(); - T* curr = head; + Ptr curr = head; while (curr != item) { @@ -172,11 +176,11 @@ namespace snmalloc #endif } - void debug_check_not_contains(T* item) + void debug_check_not_contains(Ptr item) { #ifndef NDEBUG debug_check(); - T* curr = head; + Ptr curr = head; while (curr != Terminator()) { @@ -191,8 +195,8 @@ namespace snmalloc void debug_check() { #ifndef NDEBUG - T* item = head; - T* prev = Terminator(); + Ptr item = head; + Ptr prev = Terminator(); while (item != Terminator()) { diff --git a/src/ds/helpers.h b/src/ds/helpers.h index 54e2322..a815728 100644 --- a/src/ds/helpers.h +++ b/src/ds/helpers.h @@ -143,8 +143,8 @@ namespace snmalloc }; }; - template - void ignore(T* t) + template typename Ptr> + void ignore(Ptr t) { UNUSED(t); }