Commit 38b60673 authored by Xavier Thompson's avatar Xavier Thompson

gc.hpp: Start with initial bogus node

parent f179573d
......@@ -50,13 +50,16 @@ namespace typon::fdt::lock_free
const uint _concurrency;
std::atomic<u64> * const _stamps;
std::atomic<u64> _stamp {0};
std::atomic<node *> _head {nullptr};
std::atomic<node *> _tail {nullptr};
std::atomic<node *> _head;
std::atomic<node *> _tail;
gc(uint concurrency) noexcept
: _concurrency(concurrency)
, _stamps(new std::atomic<u64>[concurrency])
{
auto first = new node(0);
_head.store(first);
_tail.store(first);
for (uint i = 0; i < _concurrency; i++)
{
_stamps[i].store(u64(-1));
......@@ -74,14 +77,7 @@ namespace typon::fdt::lock_free
auto stamp = _stamp.load();
auto node = new garbage<T> { ptr, stamp };
auto head = _head.exchange(node);
if (head)
{
head->_next.store(node);
}
else
{
_tail.store(node);
}
head->_next.store(node);
}
void leave(uint id) noexcept
......@@ -110,7 +106,7 @@ namespace typon::fdt::lock_free
void reclaim(u64 oldest) noexcept
{
auto tail = _tail.load();
while (tail)
while (true)
{
if (tail->_stamp >= oldest)
{
......@@ -141,7 +137,6 @@ namespace typon::fdt::lock_free
}
}
};
}
......
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