diff options
author | David Robillard <d@drobilla.net> | 2017-10-05 21:10:12 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-12-16 13:57:39 +0100 |
commit | 516552fe4f38ba82c72fe6ea32982c8a772f9088 (patch) | |
tree | e247dbc91057cecd20d6d00b622e30c19c428d2f /src | |
parent | 4975f1e0b17cee620a58b29232867c667c24b0e3 (diff) | |
download | ingen-516552fe4f38ba82c72fe6ea32982c8a772f9088.tar.gz ingen-516552fe4f38ba82c72fe6ea32982c8a772f9088.tar.bz2 ingen-516552fe4f38ba82c72fe6ea32982c8a772f9088.zip |
Remove Engine dependency from Task
Diffstat (limited to 'src')
-rw-r--r-- | src/server/Engine.cpp | 2 | ||||
-rw-r--r-- | src/server/Engine.hpp | 2 | ||||
-rw-r--r-- | src/server/RunContext.cpp | 14 | ||||
-rw-r--r-- | src/server/RunContext.hpp | 8 | ||||
-rw-r--r-- | 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> 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 @@ -141,6 +141,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) { if (_thread) { 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; } |