From 0f5f660fa31787e283cfb14f52d3f7969c7baaee Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 4 Jul 2018 14:02:29 +1000 Subject: [PATCH] pool: align nodes to pointer boundaries --- pool.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pool.hpp b/pool.hpp index 0b5dc36a..f4dbc4e3 100644 --- a/pool.hpp +++ b/pool.hpp @@ -19,6 +19,7 @@ #include "nocopy.hpp" #include "debug.hpp" +#include "cast.hpp" #include #include @@ -34,7 +35,7 @@ namespace util { protected: union node; - union alignas (T) node { + union alignas(node*) node { std::atomic next; char data[sizeof (T)]; }; @@ -97,7 +98,7 @@ namespace util { if (m_next.compare_exchange_weak (curr, soon)) { ++m_size; - return std::launder (reinterpret_cast (curr)); + return std::launder (util::cast::alignment (curr)); } } while (1); } @@ -105,7 +106,7 @@ namespace util { void deallocate (T *base) { - auto soon = reinterpret_cast (base); + auto soon = util::cast::alignment (base); do { node *curr = m_next;