Commit 234e5684 authored by Xavier Thompson's avatar Xavier Thompson

Refactor Scheduler::suspend

parent 2037fb43
...@@ -57,12 +57,10 @@ namespace typon ...@@ -57,12 +57,10 @@ namespace typon
return result; return result;
} }
static Deque * suspend(std::coroutine_handle<> coroutine) noexcept static auto suspend(std::coroutine_handle<> coroutine) noexcept
{ {
Worker & worker = get()._worker[thread_id]; Worker & worker = get()._worker[thread_id];
Deque * deque = worker._deque.load(); auto deque = worker.suspend(coroutine);
worker._deque.store(nullptr);
deque->suspend(coroutine);
uint id = fdt::random::random() % get()._concurrency; uint id = fdt::random::random() % get()._concurrency;
get()._worker[id].add(deque); get()._worker[id].add(deque);
return deque; return deque;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define TYPON_CORE_WORKER_HPP_INCLUDED #define TYPON_CORE_WORKER_HPP_INCLUDED
#include <atomic> #include <atomic>
#include <coroutine>
#include <mutex> #include <mutex>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
...@@ -60,6 +61,14 @@ namespace typon ...@@ -60,6 +61,14 @@ namespace typon
} }
} }
auto suspend(std::coroutine_handle<> coroutine) noexcept
{
auto deque = _deque.load();
_deque.store(nullptr);
deque->suspend(coroutine);
return deque;
}
void resume(Work & work) noexcept void resume(Work & work) noexcept
{ {
auto deque = _deque.load(); auto deque = _deque.load();
......
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