summaryrefslogtreecommitdiffstats
path: root/src/server/Task.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Task.hpp')
-rw-r--r--src/server/Task.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/server/Task.hpp b/src/server/Task.hpp
index 99fe347d..25f76260 100644
--- a/src/server/Task.hpp
+++ b/src/server/Task.hpp
@@ -24,12 +24,55 @@
#include <memory>
#include <ostream>
+#include <boost/variant/variant.hpp>
+
namespace Ingen {
namespace Server {
class BlockImpl;
class RunContext;
+struct SingleTask;
+struct MultiTask;
+struct SeqTask;
+struct ParTask;
+
+using Task = boost::variant<SingleTask, SeqTask, ParTask>;
+
+using TaskChildren = std::deque<std::unique_ptr<Task>>;
+
+struct SingleTask {
+ BlockImpl* block; ///< Block to run
+};
+
+struct MultiTask {
+ /** Prepend a child to this task. */
+ template<typename... Args>
+ void emplace_front(Args... args) {
+ children.emplace_front(new Task(std::forward<Args>(args)...));
+ }
+
+ TaskChildren children; ///< Child tasks
+};
+
+struct SeqTask : MultiTask {
+};
+
+struct ParTask : MultiTask {
+ ParTask() = default;
+
+ ParTask(ParTask&& task)
+ : done_end(task.done_end)
+ , next(task.next.load())
+ , done(task.done.load())
+ {}
+
+ unsigned done_end{0}; ///< Index of rightmost done sub-task
+ std::atomic<unsigned> next{0}; ///< Index of next sub-task
+ std::atomic<bool> done{false}; ///< Completion phase
+};
+
+ #if 0
class Task {
public:
enum class Mode {
@@ -112,6 +155,15 @@ private:
std::atomic<bool> _done; ///< Completion phase
};
+#endif
+
+void run(Task& task, RunContext& context);
+
+std::unique_ptr<Task> simplify(std::unique_ptr<Task>&& task);
+
+/** Steal a child task from this task. */
+Task* steal(ParTask& task, RunContext& context);
+
} // namespace Server
} // namespace Ingen