pool: add clone and move assignment operators
This commit is contained in:
parent
766e7d0370
commit
0bb092b92f
30
pool.hpp
30
pool.hpp
@ -62,7 +62,35 @@ namespace cruft {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
pool& operator= (pool&&);
|
||||
pool& operator= (pool &&rhs)
|
||||
{
|
||||
std::swap (m_available, rhs.m_available);
|
||||
std::swap (m_store, rhs.m_store);
|
||||
std::swap (m_capacity, rhs.m_capacity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
pool clone (void) const
|
||||
{
|
||||
pool res (m_capacity);
|
||||
memcpy (res.m_store, m_store, sizeof (T) * m_capacity);
|
||||
|
||||
res.m_available = m_available.clone ();
|
||||
|
||||
// Rebase the pointers to available data so they point into the
|
||||
// cloned object.
|
||||
auto offset = reinterpret_cast<uintptr_t> (res.m_store) - reinterpret_cast<uintptr_t> (m_store);
|
||||
auto data = res.m_available.store (
|
||||
decltype(res.m_available)::contract::I_HAVE_LOCKED_THIS_STRUCTURE
|
||||
);
|
||||
for (auto &ptr: data)
|
||||
ptr = reinterpret_cast<void*> (reinterpret_cast<uintptr_t> (ptr) + offset);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user