From 85f207e2bfe1ba8c6124643ccf3b9efa0feffa0e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 15 Mar 2018 00:01:38 -0400 Subject: Add more convenient Task creation API --- src/server/Task.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/server/Task.hpp b/src/server/Task.hpp index 2cdad71b..22f72997 100644 --- a/src/server/Task.hpp +++ b/src/server/Task.hpp @@ -38,6 +38,17 @@ public: PARALLEL ///< Elements may be run in any order in parallel }; + explicit Task(BlockImpl* block) + : _block(block) + , _mode(Mode::SINGLE) + , _done_end(0) + , _next(0) + , _done(false) + { + assert(block); + } + + Task(Mode mode, BlockImpl* block = nullptr) : _block(block) , _mode(mode) @@ -83,11 +94,22 @@ public: /** Steal a child task from this task (succeeds for PARALLEL only). */ Task* steal(RunContext& context); + /** Return the child task at the front of this task. */ + Task& front() const { + return *_children.front(); + } + /** Prepend a child to this task. */ void push_front(Task&& task) { _children.emplace_front(std::unique_ptr(new Task(std::move(task)))); } + /** Prepend a child to this task. */ + template + void emplace_front(Args... args) { + _children.emplace_front(std::unique_ptr(new Task(std::forward(args)...))); + } + Mode mode() const { return _mode; } BlockImpl* block() const { return _block; } bool done() const { return _done; } -- cgit v1.2.1