Commit e64a5f8b authored by Xavier Thompson's avatar Xavier Thompson

scheduler.hpp: Use multiple calls to Scheduler::get()

parent 2ba25c7b
...@@ -36,10 +36,9 @@ namespace typon ...@@ -36,10 +36,9 @@ namespace typon
static void schedule(std::coroutine_handle<> task) noexcept static void schedule(std::coroutine_handle<> task) noexcept
{ {
Scheduler & scheduler = get(); uint id = fdt::random::random() % get()._concurrency;
uint id = fdt::random::random() % scheduler._concurrency; get()._worker[id].add(new Deque(task));
scheduler._worker[id].add(new Deque(task)); get()._notifyer.notify_one();
scheduler._notifyer.notify_one();
} }
static void push(Continuation task) noexcept static void push(Continuation task) noexcept
...@@ -49,25 +48,23 @@ namespace typon ...@@ -49,25 +48,23 @@ namespace typon
static bool pop() noexcept static bool pop() noexcept
{ {
Scheduler & scheduler = get(); Deque * deque = get()._worker[thread_id]._deque.load();
Deque * deque = scheduler._worker[thread_id]._deque.load();
bool result = deque->pop(); bool result = deque->pop();
if (auto garbage = deque->reclaim()) if (auto garbage = deque->reclaim())
{ {
scheduler._gc.retire(garbage); get()._gc.retire(garbage);
} }
return result; return result;
} }
static Deque * suspend(std::coroutine_handle<> coroutine) noexcept static Deque * suspend(std::coroutine_handle<> coroutine) noexcept
{ {
Scheduler & scheduler = get(); Worker & worker = get()._worker[thread_id];
Worker & worker = scheduler._worker[thread_id];
Deque * deque = worker._deque.load(); Deque * deque = worker._deque.load();
worker._deque.store(nullptr); worker._deque.store(nullptr);
deque->suspend(coroutine); deque->suspend(coroutine);
uint id = fdt::random::random() % scheduler._concurrency; uint id = fdt::random::random() % get()._concurrency;
scheduler._worker[id].add(deque); get()._worker[id].add(deque);
return deque; return deque;
} }
...@@ -76,9 +73,8 @@ namespace typon ...@@ -76,9 +73,8 @@ namespace typon
auto state = deque->_state.exchange(Deque::Resumable); auto state = deque->_state.exchange(Deque::Resumable);
if (state == Deque::Empty) if (state == Deque::Empty)
{ {
Scheduler & scheduler = get(); uint id = fdt::random::random() % get()._concurrency;
uint id = fdt::random::random() % scheduler._concurrency; get()._worker[id].add(deque);
scheduler._worker[id].add(deque);
} }
get()._notifyer.notify_one(); get()._notifyer.notify_one();
} }
......
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