summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Engine.cpp2
-rw-r--r--src/server/Engine.hpp2
-rw-r--r--src/server/RunContext.cpp14
-rw-r--r--src/server/RunContext.hpp8
-rw-r--r--src/server/Task.cpp8
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;
}