parallel/stack: add move operators

This commit is contained in:
Danny Robson 2019-05-24 11:21:31 +10:00
parent fb36953135
commit 257275e0f5

View File

@ -32,8 +32,31 @@ namespace cruft::parallel {
stack (stack const &) = delete;
stack& operator=(stack const &) = delete;
stack (stack &&);
stack& operator= (stack &&);
stack (stack &&rhs):
stack (0)
{
swap (rhs);
}
stack& operator= (stack &&rhs)
{
swap (rhs);
return *this;
}
void swap (stack &rhs)
{
std::lock_guard lk0 (m_lock);
std::lock_guard lk1 (rhs.m_lock);
auto tmp = m_cursor.load ();
m_cursor = rhs.m_cursor.load ();
rhs.m_cursor = tmp;
std::swap (m_store, rhs.m_store);
std::swap (m_lock, rhs.m_lock);
}
stack (std::size_t capacity)
: m_cursor (0)
@ -42,7 +65,6 @@ namespace cruft::parallel {
CHECK_GT (capacity, 0u);
}
/// Move the value from the top of the stack into an output pointer.
///
/// The internal object will be destroyed after the output has been set.