Commit 3e1af24c authored by Xavier Thompson's avatar Xavier Thompson

Refactor scheduler.hpp and worker.hpp

parent 234e5684
......@@ -43,18 +43,12 @@ namespace typon
static void push(Continuation task) noexcept
{
get()._worker[thread_id]._deque.load()->push(task);
get()._worker[thread_id].push(task);
}
static bool pop() noexcept
{
Deque * deque = get()._worker[thread_id]._deque.load();
bool result = deque->pop();
if (auto garbage = deque->reclaim())
{
get()._gc.retire(garbage);
}
return result;
return get()._worker[thread_id].pop();
}
static auto suspend(std::coroutine_handle<> coroutine) noexcept
......@@ -145,7 +139,7 @@ namespace typon
for (uint i = 0; i < _concurrency * 2 + 1; i++)
{
uint id = fdt::random::random() % _concurrency;
work = _worker[id].try_steal();
work = _worker[id].steal();
if (work)
{
break;
......@@ -158,7 +152,7 @@ namespace typon
auto epoch = _gc.epoch(thread_id);
for (uint id = 0; id < _concurrency; id++)
{
work = _worker[id].try_steal();
work = _worker[id].steal();
if (work)
{
break;
......
......@@ -61,6 +61,23 @@ namespace typon
}
}
void add(Deque * deque) noexcept
{
std::lock_guard lock(_mutex);
_pool.push_back(deque);
}
bool try_add(Deque * deque) noexcept
{
if (!_mutex.try_lock())
{
return false;
}
std::lock_guard lock(_mutex, std::adopt_lock);
_pool.push_back(deque);
return true;
}
auto suspend(std::coroutine_handle<> coroutine) noexcept
{
auto deque = _deque.load();
......@@ -91,24 +108,23 @@ namespace typon
}
}
void add(Deque * deque) noexcept
void push(Continuation task) noexcept
{
std::lock_guard lock(_mutex);
_pool.push_back(deque);
_deque.load()->push(task);
}
bool try_add(Deque * deque) noexcept
bool pop() noexcept
{
if (!_mutex.try_lock())
Deque * deque = _deque.load();
bool result = deque->pop();
if (auto garbage = deque->reclaim())
{
return false;
_gc->retire(garbage);
}
std::lock_guard lock(_mutex, std::adopt_lock);
_pool.push_back(deque);
return true;
return result;
}
Work try_steal() noexcept
Work steal() noexcept
{
if (!_mutex.try_lock())
{
......
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