From c6bfe393f511799519022c5d9b614866edcc393b Mon Sep 17 00:00:00 2001 From: PaintDream Date: Sun, 26 May 2024 11:39:26 +0800 Subject: [PATCH] [FIX] Fix scheduling on parallel routines. --- src/iris_dispatcher.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/iris_dispatcher.h b/src/iris_dispatcher.h index d8662aa..919d0f1 100644 --- a/src/iris_dispatcher.h +++ b/src/iris_dispatcher.h @@ -627,6 +627,8 @@ namespace iris { // and it's ok to return immediately. preempt_guard_t preempt_guard(*this, 0); if (preempt_guard) { + execute_parallel(); + if (suspend_count.load(std::memory_order_acquire) == 0) { // double check for suspend_count execute_internal(); @@ -638,8 +640,6 @@ namespace iris { } else { queueing.store(queue_state_pending, std::memory_order_relaxed); } - - execute_parallel(); } } else if (parallel_task_head.load(std::memory_order_acquire) != nullptr) { preempt_guard_t preempt_guard(*this, ~size_t(0)); @@ -669,8 +669,10 @@ namespace iris { void flush() noexcept(noexcept(std::declval().async_worker.queue(std::declval(), 0))) { // if current state is executing, the executing routine will reinvoke flush() if it detected pending state while exiting // so we just need to queue a flush routine as soon as current state is idle - if (queueing.exchange(queue_state_pending, std::memory_order_acq_rel) == queue_state_idle) { - async_worker.queue(execute_t(*this), priority); + if (queueing.load(std::memory_order_acquire) != queue_state_pending) { + if (queueing.exchange(queue_state_pending, std::memory_order_acq_rel) == queue_state_idle) { + async_worker.queue(execute_t(*this), priority); + } } }