Commit 4f67c5a3 authored by Xavier Thompson's avatar Xavier Thompson

Improve event_count.hpp

parent 663bf85b
...@@ -22,25 +22,23 @@ namespace typon::fdt::lock_free ...@@ -22,25 +22,23 @@ namespace typon::fdt::lock_free
auto prepare_wait() noexcept 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 void cancel_wait() noexcept {}
{
_state.fetch_sub(1, std::memory_order_seq_cst);
}
void wait(u64 state) noexcept void wait(u64 key) noexcept
{ {
u64 state = _state.fetch_add(1, std::memory_order_acq_rel) + 1;
for(;;) for(;;)
{ {
_state.wait(state, std::memory_order_acquire); if ((state ^ key) & (~mask))
auto newstate = _state.load(std::memory_order_acquire);
if ((newstate ^ state) & (~mask))
{ {
break; 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); _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