Commit 39403da0 authored by Xavier Thompson's avatar Xavier Thompson

Improve event_count.hpp

parent e64a5f8b
......@@ -22,25 +22,23 @@ namespace typon::fdt::lock_free
auto prepare_wait() noexcept
{
return _state.fetch_add(1, std::memory_order_acq_rel);
return _state.load(std::memory_order_acquire);
}
void cancel_wait() noexcept
{
_state.fetch_sub(1, std::memory_order_seq_cst);
}
void cancel_wait() noexcept {}
void wait(u64 state) noexcept
void wait(u64 key) noexcept
{
u64 state = _state.fetch_add(1, std::memory_order_acq_rel) + 1;
for(;;)
{
_state.wait(state, std::memory_order_acquire);
auto newstate = _state.load(std::memory_order_acquire);
if ((newstate ^ state) & (~mask))
if ((state ^ key) & (~mask))
{
break;
}
state = newstate;
key = state;
_state.wait(key, std::memory_order_acquire);
state = _state.load(std::memory_order_acquire);
}
_state.fetch_sub(1, std::memory_order_seq_cst);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment