summaryrefslogtreecommitdiffstats
path: root/src/server/Task.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-11-12 19:57:56 +0100
committerDavid Robillard <d@drobilla.net>2017-11-12 19:58:13 +0100
commitf8cd75372d9c45a0a8616d89a18a5b9906ac9d54 (patch)
treeeb9b06bc00c2d3b36f1f56cbd6fad7cd33df6ae0 /src/server/Task.hpp
parenta66df006ccd3426148491f0a4c21c9facb8104ea (diff)
downloadingen-f8cd75372d9c45a0a8616d89a18a5b9906ac9d54.tar.gz
ingen-f8cd75372d9c45a0a8616d89a18a5b9906ac9d54.tar.bz2
ingen-f8cd75372d9c45a0a8616d89a18a5b9906ac9d54.zip
WIP: Clean up task implementationtasks
Diffstat (limited to 'src/server/Task.hpp')
-rw-r--r--src/server/Task.hpp85
1 files changed, 31 insertions, 54 deletions
diff --git a/src/server/Task.hpp b/src/server/Task.hpp
index 203627a1..dc81eb2a 100644
--- a/src/server/Task.hpp
+++ b/src/server/Task.hpp
@@ -19,94 +19,71 @@
#include <atomic>
#include <cassert>
-#include <deque>
-#include <functional>
-#include <ostream>
+#include <vector>
+
+#include "Work.hpp"
namespace Ingen {
namespace Server {
+class Runner;
class BlockImpl;
-class RunContext;
class Task {
public:
- enum class Mode {
- SINGLE, ///< Single block to run
- SEQUENTIAL, ///< Elements must be run sequentially in order
- PARALLEL ///< Elements may be run in any order in parallel
- };
-
- Task(Mode mode, BlockImpl* block = nullptr)
- : _block(block)
- , _mode(mode)
- , _done_end(0)
- , _next(0)
- , _done(false)
- {
- assert(!(mode == Mode::SINGLE && !block));
- }
+ using Unit = BlockImpl;
+ using IR = Work<Unit>;
+ using Mode = typename IR::Mode;
+ using Children = std::vector<Task>;
Task(Task&& task)
: _children(std::move(task._children))
- , _block(task._block)
+ , _unit(task._unit)
, _mode(task._mode)
, _done_end(task._done_end)
, _next(task._next.load())
, _done(task._done.load())
{}
- Task& operator=(Task&& task)
- {
- _children = std::move(task._children);
- _block = task._block;
- _mode = task._mode;
- _done_end = task._done_end;
- _next = task._next.load();
- _done = task._done.load();
- return *this;
- }
+ Task(const Task&) = delete;
+ Task& operator=(const Task&) = delete;
/** Run task in the given context. */
- void run(RunContext& context);
-
- /** Pretty print task to the given stream (recursively). */
- void dump(std::function<void (const std::string&)> sink, unsigned indent, bool first) const;
+ void run(Runner& context);
/** Return true iff this is an empty task. */
- bool empty() const { return _mode != Mode::SINGLE && _children.empty(); }
+ bool empty() const { return _mode != Mode::UNIT && _children.empty(); }
/** Simplify task expression. */
- static Task simplify(Task task);
+ static Task compile(const IR& source);
/** Steal a child task from this task (succeeds for PARALLEL only). */
- Task* steal(RunContext& context);
+ Task* steal(Runner& context);
- /** Prepend a child to this task. */
- void push_front(Task&& task) {
- _children.emplace_front(std::move(task));
- }
-
- Mode mode() const { return _mode; }
- BlockImpl* block() const { return _block; }
- bool done() const { return _done; }
+ Mode mode() const { return _mode; }
+ Unit* unit() const { return _unit; }
+ const Children& children() const { return _children; }
+ bool done() const { return _done; }
void set_done(bool done) { _done = done; }
private:
- typedef std::deque<Task> Children;
-
- Task(const Task&) = delete;
- Task& operator=(const Task&) = delete;
+ Task(Mode mode, Unit* unit = nullptr)
+ : _unit(unit)
+ , _mode(mode)
+ , _done_end(0)
+ , _next(0)
+ , _done(false)
+ {
+ assert(!(mode == Mode::UNIT && !unit));
+ }
- Task* get_task(RunContext& context);
+ Task* get_task(Runner& context);
- void append(Task t) {
- _children.emplace_back(std::move(t));
- }
+ void append(Task t) { _children.emplace_back(std::move(t)); }
Children _children; ///< Vector of child tasks
- BlockImpl* _block; ///< Used for SINGLE only
+ Unit* _unit; ///< Used for UNIT only
Mode _mode; ///< Execution mode
unsigned _done_end; ///< Index of rightmost done sub-task
std::atomic<unsigned> _next; ///< Index of next sub-task