From 516552fe4f38ba82c72fe6ea32982c8a772f9088 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 5 Oct 2017 21:10:12 +0200 Subject: Remove Engine dependency from Task --- src/server/Engine.cpp | 2 +- src/server/Engine.hpp | 2 +- src/server/RunContext.cpp | 14 ++++++++++++++ src/server/RunContext.hpp | 8 +++++--- src/server/Task.cpp | 8 +++----- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 8ec74829..8567ae2a 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -271,7 +271,7 @@ Engine::wait_for_tasks() } void -Engine::signal_tasks() +Engine::signal_tasks_available() { _tasks_available.notify_all(); } diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index cf13f5e6..7c553d5d 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -154,7 +154,7 @@ public: void emit_notifications(FrameTime end); bool pending_notifications(); bool wait_for_tasks(); - void signal_tasks(); + void signal_tasks_available(); Task* steal_task(unsigned start_thread); SPtr store() const; diff --git a/src/server/RunContext.cpp b/src/server/RunContext.cpp index 541f066d..b2e3f269 100644 --- a/src/server/RunContext.cpp +++ b/src/server/RunContext.cpp @@ -140,6 +140,20 @@ RunContext::emit_notifications(FrameTime end) } } +void +RunContext::claim_task(Task* task) +{ + if ((_task = task)) { + _engine.signal_tasks_available(); + } +} + +Task* +RunContext::steal_task() const +{ + return _engine.steal_task(_id + 1); +} + void RunContext::set_priority(int priority) { diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp index 099ce70f..87fb0fed 100644 --- a/src/server/RunContext.hpp +++ b/src/server/RunContext.hpp @@ -114,9 +114,11 @@ public: _nframes = nframes; } - inline void set_task(Task* task) { - _task = task; - } + /** Claim a parallel task, and signal others that work is available. */ + void claim_task(Task* task); + + /** Steal a task from some other context if possible. */ + Task* steal_task() const; void set_priority(int priority); void set_rate(SampleCount rate) { _rate = rate; } diff --git a/src/server/Task.cpp b/src/server/Task.cpp index 7f1d4327..c76c19ae 100644 --- a/src/server/Task.cpp +++ b/src/server/Task.cpp @@ -15,7 +15,6 @@ */ #include "BlockImpl.hpp" -#include "Engine.hpp" #include "Task.hpp" namespace Ingen { @@ -46,14 +45,13 @@ Task::run(RunContext& context) Task* t = steal(context); // Allow other threads to steal sub-tasks - context.set_task(this); - context.engine().signal_tasks(); + context.claim_task(this); // Run available tasks until this task is finished for (; t; t = get_task(context)) { t->run(context); } - context.set_task(nullptr); + context.claim_task(nullptr); break; } @@ -93,7 +91,7 @@ Task::get_task(RunContext& context) } // All child tasks claimed, but some are unfinished, steal a task - if ((t = context.engine().steal_task(context.id() + 1))) { + if ((t = context.steal_task())) { return t; } -- cgit v1.2.1