parallel/stack: add clone method

This commit is contained in:
Danny Robson 2019-08-02 08:13:39 +10:00
parent e723684347
commit 766e7d0370

View File

@ -44,6 +44,17 @@ namespace cruft::parallel {
return *this; return *this;
} }
stack clone (void) const
{
stack res (capacity ());
std::lock_guard lk (m_lock);
res.m_cursor = m_cursor.load ();
res.m_store = m_store;
return res;
}
/// Thread safe swapping with the supplied object /// Thread safe swapping with the supplied object
void swap (stack &rhs) void swap (stack &rhs)
@ -146,7 +157,7 @@ namespace cruft::parallel {
using index_type = std::size_t; using index_type = std::size_t;
using raw_type = std::aligned_storage_t<sizeof(ValueT), alignof(ValueT)>; using raw_type = std::aligned_storage_t<sizeof(ValueT), alignof(ValueT)>;
cruft::thread::spinlock m_lock; mutable cruft::thread::spinlock m_lock;
std::atomic<index_type> m_cursor; std::atomic<index_type> m_cursor;
std::vector<raw_type> m_store; std::vector<raw_type> m_store;
}; };