pool: align nodes to pointer boundaries
This commit is contained in:
parent
d466ed75ac
commit
0f5f660fa3
7
pool.hpp
7
pool.hpp
@ -19,6 +19,7 @@
|
||||
|
||||
#include "nocopy.hpp"
|
||||
#include "debug.hpp"
|
||||
#include "cast.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
@ -34,7 +35,7 @@ namespace util {
|
||||
protected:
|
||||
union node;
|
||||
|
||||
union alignas (T) node {
|
||||
union alignas(node*) node {
|
||||
std::atomic<node*> 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<T*> (curr));
|
||||
return std::launder (util::cast::alignment<T*> (curr));
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
@ -105,7 +106,7 @@ namespace util {
|
||||
void
|
||||
deallocate (T *base)
|
||||
{
|
||||
auto soon = reinterpret_cast<node*> (base);
|
||||
auto soon = util::cast::alignment<node*> (base);
|
||||
|
||||
do {
|
||||
node *curr = m_next;
|
||||
|
Loading…
Reference in New Issue
Block a user