atomic_t<>: extend fetch_op to support cancellation

Use std::invoke inside atomic_op/fetch_op
Remove op_fetch because it's easily replaced
Add fetch_dec_sat algorithm (conditional decrement)
This commit is contained in:
Nekotekina 2018-09-05 22:28:37 +03:00
parent ed9fb8405b
commit fb5cdf9769
10 changed files with 80 additions and 60 deletions

View file

@ -111,9 +111,10 @@ public:
// Unconditionally set next state
void state_next()
{
T _old, state = m_value.op_fetch([&](T& value)
T _old, state = m_value.atomic_op([&](T& value)
{
_old = value++;
return value;
});
(static_cast<CRT*>(this)->*transition_get(state))(_old);
@ -122,9 +123,10 @@ public:
// Unconditionally set previous state
void state_prev()
{
T _old, state = m_value.op_fetch([&](T& value)
T _old, state = m_value.atomic_op([&](T& value)
{
_old = value--;
return value;
});
(static_cast<CRT*>(this)->*transition_get(state))(_old);