51 default:
return "unknown";
57 struct root_type : std::integral_constant<transwarp::task_type, transwarp::task_type::root> {};
61 struct accept_type : std::integral_constant<transwarp::task_type, transwarp::task_type::accept> {};
65 struct accept_any_type : std::integral_constant<transwarp::task_type, transwarp::task_type::accept_any> {};
69 struct consume_type : std::integral_constant<transwarp::task_type, transwarp::task_type::consume> {};
73 struct consume_any_type : std::integral_constant<transwarp::task_type, transwarp::task_type::consume_any> {};
77 struct wait_type : std::integral_constant<transwarp::task_type, transwarp::task_type::wait> {};
81 struct wait_any_type : std::integral_constant<transwarp::task_type, transwarp::task_type::wait_any> {};
114 node& operator=(
const node&) =
delete;
134 const std::shared_ptr<std::string>&
get_name() const noexcept {
144 const std::vector<std::shared_ptr<node>>&
get_parents() const noexcept {
160 return canceled_.load();
167 std::size_t level_ = 0;
169 std::shared_ptr<std::string> name_;
170 std::shared_ptr<std::string> executor_;
171 std::vector<std::shared_ptr<node>> parents_;
172 std::size_t priority_ = 0;
173 std::shared_ptr<void> custom_data_;
174 std::atomic_bool canceled_{
false};
183 s +=
"<" + *name +
">" + seperator;
186 s +=
" id=" + std::to_string(node.
get_id());
187 s +=
" lev=" + std::to_string(node.
get_level());
190 s += seperator +
"<" + *exec +
">";
201 edge(std::shared_ptr<transwarp::node> parent, std::shared_ptr<transwarp::node> child) noexcept
202 : parent_(std::move(parent)), child_(std::move(child))
207 edge& operator=(
const edge&) =
default;
212 const std::shared_ptr<transwarp::node>&
get_parent() const noexcept {
217 const std::shared_ptr<transwarp::node>&
get_child() const noexcept {
222 std::shared_ptr<transwarp::node> parent_;
223 std::shared_ptr<transwarp::node> child_;
233 inline std::string
to_string(
const std::vector<transwarp::edge>& graph,
const std::string& separator=
"\n") {
234 std::string dot =
"digraph {" + separator;
235 for (
const auto&
edge : graph) {
249 virtual std::string
get_name()
const = 0;
254 virtual void execute(
const std::function<
void()>&
functor,
const std::shared_ptr<transwarp::node>&
node) = 0;
279 virtual ~
itask() =
default;
281 virtual void set_executor(std::shared_ptr<transwarp::executor>
executor) = 0;
282 virtual void set_executor_all(std::shared_ptr<transwarp::executor> executor) = 0;
283 virtual void remove_executor() = 0;
284 virtual void remove_executor_all() = 0;
285 virtual void set_priority(std::size_t priority) = 0;
286 virtual void set_priority_all(std::size_t priority) = 0;
287 virtual void reset_priority() = 0;
288 virtual void reset_priority_all() = 0;
289 virtual void set_custom_data(std::shared_ptr<void> custom_data) = 0;
290 virtual void set_custom_data_all(std::shared_ptr<void> custom_data) = 0;
291 virtual void remove_custom_data() = 0;
292 virtual void remove_custom_data_all() = 0;
293 virtual const std::shared_ptr<transwarp::node>& get_node()
const noexcept = 0;
294 virtual void add_listener(std::shared_ptr<transwarp::listener>
listener) = 0;
295 virtual void remove_listener(
const std::shared_ptr<transwarp::listener>& listener) = 0;
296 virtual void schedule() = 0;
298 virtual void schedule(
bool reset) = 0;
300 virtual void schedule_all() = 0;
302 virtual void schedule_all(
bool reset_all) = 0;
308 virtual void set_exception(std::exception_ptr exception) = 0;
309 virtual bool was_scheduled()
const noexcept = 0;
310 virtual void wait()
const = 0;
311 virtual bool is_ready()
const = 0;
312 virtual bool has_result()
const = 0;
313 virtual void reset() = 0;
314 virtual void reset_all() = 0;
315 virtual void cancel(
bool enabled) noexcept = 0;
316 virtual void cancel_all(
bool enabled) noexcept = 0;
317 virtual std::vector<transwarp::edge> get_graph()
const = 0;
328 virtual void visit_depth(
const std::function<
void(
itask&)>& visitor) = 0;
329 virtual void unvisit() noexcept = 0;
330 virtual void set_node_id(std::size_t
id) noexcept = 0;
337 using type =
typename std::remove_reference<typename std::remove_const<T>::type>::type;
344 using type =
typename std::result_of<decltype(&std::shared_future<T>::get)(std::shared_future<T>)>::type;
349 template<
typename ResultType>
352 using result_type = ResultType;
354 virtual ~
task() =
default;
356 virtual void set_value(
const typename transwarp::remove_refc<result_type>::type& value) = 0;
357 virtual void set_value(
typename transwarp::remove_refc<result_type>::type&& value) = 0;
358 virtual const std::shared_future<result_type>& get_future()
const noexcept = 0;
359 virtual typename transwarp::result_info<result_type>::type
get()
const = 0;
363 template<
typename ResultType>
366 using result_type = ResultType&;
368 virtual ~
task() =
default;
370 virtual void set_value(
typename transwarp::remove_refc<result_type>::type& value) = 0;
371 virtual const std::shared_future<result_type>& get_future()
const noexcept = 0;
372 virtual typename transwarp::result_info<result_type>::type
get()
const = 0;
379 using result_type = void;
381 virtual ~
task() =
default;
383 virtual void set_value() = 0;
384 virtual const std::shared_future<result_type>& get_future()
const noexcept = 0;
385 virtual result_type
get()
const = 0;
393 : std::runtime_error(message)
436 return transwarp_node_;
442 if (transwarp_node_->is_canceled()) {
451 std::shared_ptr<transwarp::node> transwarp_node_;
466 static void set_level(
transwarp::node& node, std::size_t level) noexcept {
474 static void set_name(
transwarp::node& node, std::shared_ptr<std::string> name) noexcept {
480 node.executor_ = std::move(executor);
482 node.executor_.reset();
486 static void add_parent(
transwarp::node& node, std::shared_ptr<transwarp::node> parent) {
487 node.parents_.push_back(std::move(parent));
490 static void set_priority(
transwarp::node& node, std::size_t priority) noexcept {
491 node.priority_ = priority;
494 static void set_custom_data(
transwarp::node& node, std::shared_ptr<void> custom_data) {
496 node.custom_data_ = std::move(custom_data);
498 node.custom_data_.reset();
502 static void set_canceled(
transwarp::node& node,
bool enabled) noexcept {
503 node.canceled_ = enabled;
516 if (n_threads == 0) {
519 const auto n_target = threads_.size() + n_threads;
520 while (threads_.size() < n_target) {
523 thread = std::thread(&thread_pool::worker,
this);
529 threads_.push_back(std::move(thread));
548 void push(
const std::function<
void()>&
functor) {
550 std::lock_guard<std::mutex> lock(mutex_);
553 cond_var_.notify_one();
562 std::unique_lock<std::mutex> lock(mutex_);
563 cond_var_.wait(lock, [
this]{
564 return done_ || !functors_.empty();
566 if (done_ && functors_.empty()) {
569 functor = functors_.front();
578 std::lock_guard<std::mutex> lock(mutex_);
581 cond_var_.notify_all();
582 for (
auto& thread : threads_) {
589 std::vector<std::thread> threads_;
590 std::queue<std::function<void()>> functors_;
591 std::condition_variable cond_var_;
596 template<
typename Result,
typename Task,
typename... Args>
597 Result run_task(std::size_t node_id,
const Task&
task, Args&&... args) {
598 auto t = task.lock();
602 if (t->node_->is_canceled()) {
605 return t->functor_(std::forward<Args>(args)...);
609 inline void wait_for_all() {}
612 template<
typename Future,
typename... ParentResults>
613 void wait_for_all(
const Future& future,
const std::shared_future<ParentResults>& ...futures) {
619 template<
typename FutureResult>
620 FutureResult wait_for_any_impl() {
624 template<
typename FutureResult,
typename Future,
typename... ParentResults>
625 FutureResult wait_for_any_impl(
const Future& future,
const std::shared_future<ParentResults>& ...futures) {
626 const auto status = future.wait_for(std::chrono::microseconds(1));
627 if (status == std::future_status::ready) {
630 return transwarp::detail::wait_for_any_impl<FutureResult>(futures...);
634 template<
typename FutureResult,
typename... ParentResults>
635 FutureResult
wait_for_any(
const std::shared_future<ParentResults>& ...futures) {
637 auto future = transwarp::detail::wait_for_any_impl<FutureResult>(futures...);
638 if (future.valid()) {
645 template<
typename TaskType,
bool done,
int total,
int... n>
647 template<
typename Result,
typename Task,
typename... ParentResults>
648 static Result work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
650 work<Result>(node_id, task, futures);
654 template<
int total,
int... n>
656 template<
typename Result,
typename Task,
typename... ParentResults>
657 static Result work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>&) {
658 return transwarp::detail::run_task<Result>(node_id, task);
662 template<
int total,
int... n>
664 template<
typename Result,
typename Task,
typename... ParentResults>
665 static Result work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
667 return transwarp::detail::run_task<Result>(node_id, task, std::get<n>(futures)...);
671 template<
int total,
int... n>
673 template<
typename Result,
typename Task,
typename... ParentResults>
674 static Result
work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
675 using future_t =
typename std::remove_reference<decltype(std::get<0>(futures))>::type;
676 auto future = transwarp::detail::wait_for_any<future_t>(std::get<n>(futures)...);
677 return transwarp::detail::run_task<Result>(node_id, task, future);
681 template<
int total,
int... n>
683 template<
typename Result,
typename Task,
typename... ParentResults>
684 static Result work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
686 return transwarp::detail::run_task<Result>(node_id, task, std::get<n>(futures).
get()...);
690 template<
int total,
int... n>
692 template<
typename Result,
typename Task,
typename... ParentResults>
693 static Result
work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
694 using future_t =
typename std::remove_reference<decltype(std::get<0>(futures))>::type;
695 auto future = transwarp::detail::wait_for_any<future_t>(std::get<n>(futures)...);
696 return transwarp::detail::run_task<Result>(node_id, task, future.get());
700 template<
int total,
int... n>
702 template<
typename Result,
typename Task,
typename... ParentResults>
703 static Result
work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
705 get_all(std::get<n>(futures)...);
706 return transwarp::detail::run_task<Result>(node_id, task);
708 template<
typename T,
typename... Args>
709 static void get_all(
const T& arg,
const Args& ...args) {
713 static void get_all() {}
716 template<
int total,
int... n>
718 template<
typename Result,
typename Task,
typename... ParentResults>
719 static Result work(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
720 while (!
wait(std::get<n>(futures)...));
721 return transwarp::detail::run_task<Result>(node_id, task);
723 template<
typename T,
typename... Args>
724 static bool wait(
const T& arg,
const Args& ...args) {
725 const auto status = arg.wait_for(std::chrono::microseconds(1));
726 if (status == std::future_status::ready) {
730 return wait(args...);
740 template<
typename TaskType,
typename Result,
typename Task,
typename... ParentResults>
741 Result
call_with_futures(std::size_t node_id,
const Task& task,
const std::tuple<std::shared_future<ParentResults>...>& futures) {
742 constexpr std::size_t n = std::tuple_size<std::tuple<std::shared_future<ParentResults>...>>::value;
744 work<Result>(node_id, task, futures);
751 template<std::size_t end, std::size_t idx, std::size_t... i>
754 template<std::size_t end, std::size_t... i>
759 template<std::
size_t b, std::
size_t e>
764 template<
typename Functor,
typename... ParentResults>
767 template<std::size_t i, std::size_t... j,
typename Functor,
typename... ParentResults>
769 auto ptr = std::get<i>(t);
779 template<
typename Functor,
typename... ParentResults>
781 constexpr std::size_t n = std::tuple_size<std::tuple<std::shared_ptr<transwarp::task<ParentResults>>...>>::value;
782 using index_t =
typename transwarp::detail::index_range<0, n>::type;
783 transwarp::detail::call_with_each_index(index_t(), f, t);
786 template<
int offset,
typename... ParentResults>
788 static void work(
const std::tuple<std::shared_ptr<
transwarp::task<ParentResults>>...>& source, std::tuple<std::shared_future<ParentResults>...>& target) {
789 std::get<offset>(target) = std::get<offset>(source)->get_future();
794 template<
typename... ParentResults>
800 template<
typename... ParentResults>
802 std::tuple<std::shared_future<ParentResults>...>
result;
813 transwarp::detail::node_manip::add_parent(*node_, task.get_node());
814 if (node_->get_level() <= task.get_node()->get_level()) {
816 transwarp::detail::node_manip::set_level(*node_, task.get_node()->get_level() + 1);
820 std::shared_ptr<transwarp::node>& node_;
829 task.set_node_id(id_++);
837 explicit graph_visitor(std::vector<transwarp::edge>& graph) noexcept
841 const auto&
node = task.get_node();
843 graph_.emplace_back(parent,
node);
847 std::vector<transwarp::edge>& graph_;
853 : reset_(reset), executor_(executor) {}
856 task.schedule_impl(reset_, executor_);
866 template<
typename Task>
867 void operator()(Task& task)
const {
875 : enabled_(enabled) {}
878 task.cancel(enabled_);
887 : executor_(std::move(executor)) {}
890 task.set_executor(executor_);
893 std::shared_ptr<transwarp::executor> executor_;
900 task.remove_executor();
907 : priority_(priority) {}
910 task.set_priority(priority_);
913 std::size_t priority_;
920 task.reset_priority();
927 : custom_data_(std::move(custom_data)) {}
930 task.set_custom_data(custom_data_);
933 std::shared_ptr<void> custom_data_;
940 task.remove_custom_data();
950 tasks_.push_back(&task);
953 std::vector<transwarp::itask*>& tasks_;
959 : visitor_(visitor) {}
962 task.visit_depth(visitor_);
965 const std::function<void(transwarp::itask&)>& visitor_;
977 template<
typename TaskType,
typename Functor,
typename... ParentResults>
979 static_assert(std::is_same<TaskType, transwarp::root_type>::value ||
980 std::is_same<TaskType, transwarp::accept_type>::value ||
981 std::is_same<TaskType, transwarp::accept_any_type>::value ||
982 std::is_same<TaskType, transwarp::consume_type>::value ||
983 std::is_same<TaskType, transwarp::consume_any_type>::value ||
984 std::is_same<TaskType, transwarp::wait_type>::value ||
985 std::is_same<TaskType, transwarp::wait_any_type>::value,
986 "Invalid task type, must be one of: root, accept, accept_any, consume, consume_any, wait, wait_any");
989 template<
typename Functor,
typename... ParentResults>
991 static_assert(
sizeof...(ParentResults) == 0,
"A root task cannot have parent tasks");
992 using type = decltype(std::declval<Functor>()());
995 template<
typename Functor,
typename... ParentResults>
997 static_assert(
sizeof...(ParentResults) > 0,
"An accept task must have at least one parent");
998 using type = decltype(std::declval<Functor>()(std::declval<std::shared_future<ParentResults>>()...));
1001 template<
typename Functor,
typename... ParentResults>
1003 static_assert(
sizeof...(ParentResults) > 0,
"An accept_any task must have at least one parent");
1004 using arg_t =
typename std::tuple_element<0, std::tuple<ParentResults...>>
::type;
1005 using type = decltype(std::declval<Functor>()(std::declval<std::shared_future<arg_t>>()));
1008 template<
typename Functor,
typename... ParentResults>
1010 static_assert(
sizeof...(ParentResults) > 0,
"A consume task must have at least one parent");
1011 using type = decltype(std::declval<Functor>()(std::declval<ParentResults>()...));
1014 template<
typename Functor,
typename... ParentResults>
1016 static_assert(
sizeof...(ParentResults) > 0,
"A consume_any task must have at least one parent");
1017 using arg_t =
typename std::tuple_element<0, std::tuple<ParentResults...>>
::type;
1018 using type = decltype(std::declval<Functor>()(std::declval<arg_t>()));
1021 template<
typename Functor,
typename... ParentResults>
1023 static_assert(
sizeof...(ParentResults) > 0,
"A wait task must have at least one parent");
1024 using type = decltype(std::declval<Functor>()());
1027 template<
typename Functor,
typename... ParentResults>
1029 static_assert(
sizeof...(ParentResults) > 0,
"A wait_any task must have at least one parent");
1030 using type = decltype(std::declval<Functor>()());
1033 template<
bool is_transwarp_functor>
1038 template<
typename Functor>
1039 void operator()(Functor&
functor, std::shared_ptr<transwarp::node>
node)
const noexcept {
1040 functor.transwarp_node_ = std::move(node);
1046 template<
typename Functor>
1047 void operator()(Functor&, std::shared_ptr<transwarp::node>)
const noexcept {}
1051 template<
typename Functor>
1057 template<
typename ResultType,
typename Value>
1059 std::promise<ResultType> promise;
1060 promise.set_value(std::forward<Value>(value));
1061 return promise.get_future();
1066 std::promise<void> promise;
1067 promise.set_value();
1068 return promise.get_future();
1072 template<
typename ResultType>
1077 std::promise<ResultType> promise;
1078 promise.set_exception(exception);
1079 return promise.get_future();
1099 return "transwarp::sequential";
1103 void execute(
const std::function<
void()>&
functor,
const std::shared_ptr<transwarp::node>&)
override {
1113 explicit parallel(std::size_t n_threads)
1125 return "transwarp::parallel";
1129 void execute(
const std::function<
void()>&
functor,
const std::shared_ptr<transwarp::node>&)
override {
1143 template<
typename ResultType,
typename TaskType,
typename Functor,
typename... ParentResults>
1145 public std::enable_shared_from_this<task_impl_base<ResultType, TaskType, Functor, ParentResults...>> {
1151 using result_type = ResultType;
1160 executor_ = std::move(executor);
1161 transwarp::detail::node_manip::set_executor(*node_, std::make_shared<std::string>(executor_->get_name()));
1169 visit_depth_all(visitor);
1176 transwarp::detail::node_manip::set_executor(*node_,
nullptr);
1183 visit_depth_all(visitor);
1190 transwarp::detail::node_manip::set_priority(*node_, priority);
1198 visit_depth_all(visitor);
1204 transwarp::detail::node_manip::set_priority(*node_, 0);
1211 visit_depth_all(visitor);
1221 transwarp::detail::node_manip::set_custom_data(*node_, std::move(custom_data));
1229 visit_depth_all(visitor);
1235 transwarp::detail::node_manip::set_custom_data(*node_,
nullptr);
1242 visit_depth_all(visitor);
1246 const std::shared_future<result_type>&
get_future() const noexcept
override {
1251 const std::shared_ptr<transwarp::node>&
get_node() const noexcept
override {
1260 listeners_.push_back(std::move(listener));
1268 listeners_.erase(std::remove(listeners_.begin(), listeners_.end(), listener), listeners_.end());
1276 this->schedule_impl(
true);
1285 this->schedule_impl(reset);
1293 this->schedule_impl(
true, &executor);
1302 this->schedule_impl(reset, &executor);
1344 schedule_all_impl(
true, type);
1352 schedule_all_impl(
true, type, &executor);
1361 schedule_all_impl(reset_all, type);
1370 schedule_all_impl(reset_all, type, &executor);
1377 future_ = transwarp::detail::make_future_with_exception<result_type>(exception);
1378 schedule_mode_ =
false;
1384 return future_.valid();
1398 return future_.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
1409 future_ = std::shared_future<result_type>();
1410 schedule_mode_ =
true;
1417 visit_depth_all(visitor);
1424 void cancel(
bool enabled) noexcept
override {
1425 transwarp::detail::node_manip::set_canceled(*node_, enabled);
1434 visit_depth_all(visitor);
1441 std::vector<transwarp::edge> graph;
1449 template<
typename F>
1452 : node_(std::make_shared<transwarp::
node>()),
1453 functor_(std::forward<F>(
functor)),
1454 parents_(std::make_tuple(std::move(parents)...))
1456 transwarp::detail::node_manip::set_type(*node_, task_type::value);
1457 transwarp::detail::node_manip::set_name(*node_, (has_name ? std::make_shared<std::string>(std::move(name)) :
nullptr));
1467 if (future_.valid() && future_.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
1474 if (!future_.valid()) {
1479 bool schedule_mode_ =
true;
1480 std::shared_future<result_type> future_;
1484 template<
typename R,
typename T,
typename... A>
1485 friend R transwarp::detail::run_task(std::size_t,
const T&, A&&...);
1488 void set_node_id(std::size_t
id) noexcept
override {
1489 transwarp::detail::node_manip::set_id(*node_,
id);
1497 if (schedule_mode_ && !node_->is_canceled() && (reset || !future_.valid())) {
1498 std::weak_ptr<task_impl_base>
self = this->shared_from_this();
1500 auto pack_task = std::make_shared<std::packaged_task<result_type()>>(
1503 node_->get_id(),
self, std::move(futures)));
1505 future_ = pack_task->get_future();
1506 auto callable = [pack_task,
self] {
1507 if (
const auto t =
self.lock()) {
1511 if (
const auto t =
self.lock()) {
1516 executor_->execute(callable, node_);
1517 }
else if (executor) {
1518 executor->execute(callable, node_);
1530 if (!node_->is_canceled()) {
1534 visit_breadth_all(visitor);
1537 visit_depth_all(visitor);
1546 template<
typename Visitor>
1547 void visit_breadth_all(Visitor& visitor) {
1548 if (breadth_tasks_.empty()) {
1549 breadth_tasks_.reserve(node_->get_id() + 1);
1553 const auto l_level = l->get_node()->get_level();
1554 const auto l_id = l->get_node()->get_id();
1555 const auto r_level = r->get_node()->get_level();
1556 const auto r_id = r->get_node()->get_id();
1557 return std::tie(l_level, l_id) < std::tie(r_level, r_id);
1559 std::sort(breadth_tasks_.begin(), breadth_tasks_.end(), compare);
1561 for (
auto task : breadth_tasks_) {
1567 template<
typename Visitor>
1568 void visit_depth_all(Visitor& visitor) {
1569 if (depth_tasks_.empty()) {
1570 depth_tasks_.reserve(node_->get_id() + 1);
1574 for (
auto task : depth_tasks_) {
1580 void visit_depth(
const std::function<
void(
transwarp::itask&)>& visitor)
override {
1589 void unvisit() noexcept
override {
1598 for (
const auto& listener : listeners_) {
1599 listener->handle_event(type, this->
get_node());
1603 std::shared_ptr<transwarp::node> node_;
1605 std::tuple<std::shared_ptr<transwarp::task<ParentResults>>...> parents_;
1606 bool visited_ =
false;
1607 std::shared_ptr<transwarp::executor> executor_;
1608 std::vector<std::shared_ptr<transwarp::listener>> listeners_;
1609 std::vector<transwarp::itask*> depth_tasks_;
1610 std::vector<transwarp::itask*> breadth_tasks_;
1618 template<
typename ResultType,
typename TaskType,
typename Functor,
typename... ParentResults>
1625 using result_type = ResultType;
1629 void set_value(
const typename transwarp::remove_refc<result_type>::type& value)
override {
1630 set_value_impl(value);
1635 void set_value(
typename transwarp::remove_refc<result_type>::type&& value)
override {
1636 set_value_impl(value);
1642 typename transwarp::result_info<result_type>::type
get()
const override {
1644 return this->future_.get();
1649 template<
typename F>
1656 template<
typename F>
1659 : transwarp::detail::task_impl_base<
result_type,
task_type, Functor, ParentResults...>(false,
"", std::forward<F>(
functor), std::move(parents)...)
1664 template<
typename T>
1665 void set_value_impl(T&& value) {
1667 this->future_ = transwarp::detail::make_future_with_value<result_type>(std::forward<T>(value));
1668 this->schedule_mode_ =
false;
1677 template<
typename ResultType,
typename TaskType,
typename Functor,
typename... ParentResults>
1684 using result_type = ResultType&;
1688 void set_value(
typename transwarp::remove_refc<result_type>::type& value)
override {
1689 set_value_impl(value);
1695 typename transwarp::result_info<result_type>::type
get()
const override {
1696 this->ensure_task_was_scheduled();
1697 return this->future_.get();
1702 template<
typename F>
1706 : transwarp::detail::
task_impl_base<result_type,
task_type, Functor, ParentResults...>(true, std::move(name), std::forward<F>(
functor), std::move(parents)...)
1709 template<
typename F>
1712 : transwarp::detail::task_impl_base<result_type,
task_type, Functor, ParentResults...>(false,
"", std::forward<F>(
functor), std::move(parents)...)
1717 template<
typename T>
1718 void set_value_impl(T&& value) {
1719 this->ensure_task_not_running();
1720 this->future_ = transwarp::detail::make_future_with_value<result_type>(std::forward<T>(value));
1721 this->schedule_mode_ =
false;
1730 template<
typename TaskType,
typename Functor,
typename... ParentResults>
1737 using result_type = void;
1744 this->schedule_mode_ =
false;
1750 void get()
const override {
1752 this->future_.get();
1757 template<
typename F>
1764 template<
typename F>
1767 : transwarp::detail::task_impl_base<
result_type,
task_type, Functor, ParentResults...>(false,
"", std::forward<F>(
functor), std::move(parents)...)
1778 template<
typename TaskType,
typename Functor,
typename... ParentResults>
1789 template<typename F, typename = typename std::enable_if<std::is_same<Functor, typename std::decay<F>::type>::value>::type>
1793 : transwarp::detail::task_impl_proxy<
result_type,
task_type, Functor, ParentResults...>(std::move(name), std::forward<F>(
functor), std::move(parents)...)
1798 template<typename F, typename = typename std::enable_if<std::is_same<Functor, typename std::decay<F>::type>::value>::type>
1801 : transwarp::detail::task_impl_proxy<
result_type,
task_type, Functor, ParentResults...>(std::forward<F>(
functor), std::move(parents)...)
1814 template<
typename ResultType>
1824 template<typename T, typename = typename std::enable_if<std::is_same<result_type, typename std::decay<T>::type>::value>::type>
1828 :
value_task(true, std::move(name), std::forward<T>(value))
1832 template<typename T, typename = typename std::enable_if<std::is_same<result_type, typename std::decay<T>::type>::value>::type>
1835 :
value_task(false,
"", std::forward<T>(value))
1861 transwarp::detail::node_manip::set_priority(*node_, priority);
1872 transwarp::detail::node_manip::set_priority(*node_, 0);
1886 transwarp::detail::node_manip::set_custom_data(*node_, std::move(custom_data));
1897 transwarp::detail::node_manip::set_custom_data(*node_,
nullptr);
1906 const std::shared_future<result_type>&
get_future() const noexcept
override {
1911 const std::shared_ptr<transwarp::node>&
get_node() const noexcept
override {
1958 void set_value(
const typename transwarp::remove_refc<result_type>::type& value)
override {
1959 future_ = transwarp::detail::make_future_with_value<result_type>(value);
1963 void set_value(
typename transwarp::remove_refc<result_type>::type&& value)
override {
1964 future_ = transwarp::detail::make_future_with_value<result_type>(value);
1969 future_ = transwarp::detail::make_future_with_exception<result_type>(exception);
1991 typename transwarp::result_info<result_type>::type
get()
const override {
1992 return future_.get();
2014 template<
typename T>
2016 value_task(
bool has_name, std::string name, T&& value)
2017 : node_(std::make_shared<transwarp::
node>()),
2018 future_(transwarp::detail::make_future_with_value<
result_type>(std::forward<T>(value)))
2020 transwarp::detail::node_manip::set_type(*node_, task_type::value);
2021 transwarp::detail::node_manip::set_name(*node_, (has_name ? std::make_shared<std::string>(std::move(name)) :
nullptr));
2025 void set_node_id(std::size_t
id) noexcept
override {
2026 transwarp::detail::node_manip::set_id(*node_,
id);
2033 void visit_depth(
const std::function<
void(
transwarp::itask&)>& visitor)
override {
2041 void unvisit() noexcept
override {
2045 std::shared_ptr<transwarp::node> node_;
2046 std::shared_future<result_type> future_;
2047 bool visited_ =
false;
2052 template<
typename TaskType,
typename Functor,
typename... Parents>
2053 auto make_task(TaskType, std::string name, Functor&&
functor, std::shared_ptr<Parents>... parents)
2054 -> decltype(std::make_shared<
transwarp::task_impl<TaskType,
typename std::decay<Functor>::type,
typename Parents::result_type...>>(std::move(name), std::forward<Functor>(
functor), std::move(parents)...)) {
2055 return std::make_shared<transwarp::task_impl<TaskType, typename std::decay<Functor>::type,
typename Parents::result_type...>>(std::move(name), std::forward<Functor>(
functor), std::move(parents)...);
2059 template<
typename TaskType,
typename Functor,
typename... Parents>
2061 -> decltype(std::make_shared<
transwarp::task_impl<TaskType,
typename std::decay<Functor>::type,
typename Parents::result_type...>>(std::forward<Functor>(
functor), std::move(parents)...)) {
2062 return std::make_shared<transwarp::task_impl<TaskType, typename std::decay<Functor>::type,
typename Parents::result_type...>>(std::forward<Functor>(
functor), std::move(parents)...);
2067 template<
typename Value>
2069 -> decltype(std::make_shared<
transwarp::value_task<
typename std::decay<Value>::type>>(std::move(name), std::forward<Value>(value))) {
2070 return std::make_shared<transwarp::value_task<typename std::decay<Value>::type>>(std::move(name), std::forward<Value>(value));
2074 template<
typename Value>
2076 -> decltype(std::make_shared<
transwarp::value_task<
typename std::decay<Value>::type>>(std::forward<Value>(value))) {
2077 return std::make_shared<transwarp::value_task<typename std::decay<Value>::type>>(std::forward<Value>(value));
void set_custom_data_all(std::shared_ptr< void > custom_data) override
Assigns custom data to all tasks. transwarp will not directly use this. This is only useful if someth...
Definition: transwarp.h:1226
void set_value(const typename transwarp::remove_refc< result_type >::type &value) override
Assigns a value to this task.
Definition: transwarp.h:1958
constexpr transwarp::wait_any_type wait_any
The wait_any task tag.
Definition: transwarp.h:82
void remove_custom_data_all() override
Removes custom data from all tasks.
Definition: transwarp.h:1901
The executor interface.
Definition: transwarp.h:244
Exception thrown when a task was destroyed prematurely.
Definition: transwarp.h:408
A simple thread pool used to execute tasks in parallel.
Definition: transwarp.h:510
void cancel_all(bool) noexceptoverride
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:2005
void operator()(const transwarp::itask &task) const
Definition: transwarp.h:812
Node manipulation.
Definition: transwarp.h:460
TaskType task_type
The task type.
Definition: transwarp.h:1681
Generates a graph.
Definition: transwarp.h:836
void set_value(typename transwarp::remove_refc< result_type >::type &value) override
Assigns a value to this task. Scheduling will have no effect after a value has been set...
Definition: transwarp.h:1688
The consume type. Used for tag dispatch.
Definition: transwarp.h:69
void schedule_all(transwarp::executor &) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1937
Removes the executor from the given task.
Definition: transwarp.h:897
Definition: transwarp.h:749
void reset_priority_all() override
Resets the priority of all tasks to 0.
Definition: transwarp.h:1208
Definition: transwarp.h:101
TaskType task_type
The task type.
Definition: transwarp.h:1734
void set_exception(std::exception_ptr exception) override
Assigns an exception to this task.
Definition: transwarp.h:1968
void schedule_all(bool reset_all) override
Schedules all tasks in the graph for execution on the caller thread. The task-specific executors get ...
Definition: transwarp.h:1325
void ensure_task_was_scheduled() const
Checks if the task was scheduled and throws transwarp::transwarp_error if it's not.
Definition: transwarp.h:1473
Sets parents and level of the node.
Definition: transwarp.h:808
value_task(std::string name, T &&value)
A value task is defined by name and value. name is optional, see overload.
Definition: transwarp.h:1827
void set_executor(std::shared_ptr< transwarp::executor >) override
No-op because a value task never runs.
Definition: transwarp.h:1847
void set_executor_all(std::shared_ptr< transwarp::executor > executor) override
Assigns an executor to all tasks which takes precedence over the executor provided in schedule() or s...
Definition: transwarp.h:1166
bool was_scheduled() const noexceptoverride
Returns whether the task was scheduled and not reset afterwards. This means that the underlying futur...
Definition: transwarp.h:1383
void wait_for_all(const Future &future, const std::shared_future< ParentResults > &...futures)
Waits for all futures to finish.
Definition: transwarp.h:613
void cancel(bool) noexceptoverride
No-op because a value task never runs.
Definition: transwarp.h:2002
just before a task is scheduled (handle_event called on thread of caller to schedule()) ...
void schedule_all() override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1934
just before a task finishes running (handle_event called on thread that task is run on) ...
void schedule_all(transwarp::executor &executor, bool reset_all) override
Schedules all tasks in the graph for execution using the provided executor. The task-specific executo...
Definition: transwarp.h:1334
std::string get_name() const override
Returns the name of the executor.
Definition: transwarp.h:1124
Assigns a priority to the given task.
Definition: transwarp.h:905
void schedule(transwarp::executor &executor) override
Schedules this task for execution using the provided executor. The task-specific executor gets preced...
Definition: transwarp.h:1291
Assigns an executor to the given task.
Definition: transwarp.h:885
Unvisits the given task.
Definition: transwarp.h:969
void set_priority(std::size_t priority) override
Sets a task priority (defaults to 0). transwarp will not directly use this. This is only useful if so...
Definition: transwarp.h:1860
void cancel_all(bool enabled) noexceptoverride
If enabled then all pending tasks in the graph are canceled which will throw transwarp::task_canceled...
Definition: transwarp.h:1432
void remove_custom_data() override
Removes custom data from this task.
Definition: transwarp.h:1233
void set_custom_data_all(std::shared_ptr< void > custom_data) override
Assigns custom data to all tasks. transwarp will not directly use this. This is only useful if someth...
Definition: transwarp.h:1891
std::tuple< std::shared_future< ParentResults >...> get_futures(const std::tuple< std::shared_ptr< transwarp::task< ParentResults >>...> &input)
Returns the futures from the given tasks.
Definition: transwarp.h:801
void schedule_all(transwarp::schedule_type type, bool reset_all) override
Schedules all tasks in the graph for execution on the caller thread. The task-specific executors get ...
Definition: transwarp.h:1359
Scheduling according to a breadth-first search (default)
void schedule_all() override
Schedules all tasks in the graph for execution on the caller thread. The task-specific executors get ...
Definition: transwarp.h:1308
void set_executor(std::shared_ptr< transwarp::executor > executor) override
Assigns an executor to this task which takes precedence over the executor provided in schedule() or s...
Definition: transwarp.h:1155
static Result work(std::size_t node_id, const Task &task, const std::tuple< std::shared_future< ParentResults >...> &futures)
Definition: transwarp.h:693
void set_custom_data(std::shared_ptr< void > custom_data) override
Assigns custom data to this task. transwarp will not directly use this. This is only useful if someth...
Definition: transwarp.h:1882
Removes reference and const from a type.
Definition: transwarp.h:336
The task class (non-void result type)
Definition: transwarp.h:350
value_task(T &&value)
This overload is for omitting the task name.
Definition: transwarp.h:1834
Definition: transwarp.h:760
void schedule_all(transwarp::executor &executor, transwarp::schedule_type type, bool reset_all) override
Schedules all tasks in the graph for execution using the provided executor. The task-specific executo...
Definition: transwarp.h:1368
decltype(std::declval< Functor >()(std::declval< std::shared_future< arg_t >>())) type
using first type as reference
Definition: transwarp.h:1005
void reset_priority_all() override
Resets the priority of all tasks to 0.
Definition: transwarp.h:1876
void set_priority(std::size_t priority) override
Sets a task priority (defaults to 0). transwarp will not directly use this. This is only useful if so...
Definition: transwarp.h:1188
const std::shared_ptr< std::string > & get_executor() const noexcept
The optional, task-specific executor (may be null)
Definition: transwarp.h:139
void assign_node_if(Functor &functor, std::shared_ptr< transwarp::node > node) noexcept
Assigns the node to the given functor if the functor is a subclass of transwarp::functor.
Definition: transwarp.h:1052
void reset() override
Resets the future of this task.
Definition: transwarp.h:1407
const std::vector< std::shared_ptr< node > > & get_parents() const noexcept
The task's parents (may be empty)
Definition: transwarp.h:144
decltype(std::declval< Functor >()(std::declval< arg_t >())) type
using first type as reference
Definition: transwarp.h:1018
Definition: transwarp.h:747
The task's functor accepts the first parent future that becomes ready.
Definition: transwarp.h:646
The consume_any type. Used for tag dispatch.
Definition: transwarp.h:73
ResultType result_type
The result type of this task.
Definition: transwarp.h:1625
void set_custom_data(std::shared_ptr< void > custom_data) override
Assigns custom data to this task. transwarp will not directly use this. This is only useful if someth...
Definition: transwarp.h:1216
bool was_scheduled() const noexceptoverride
Returns true because a value task is scheduled once on construction.
Definition: transwarp.h:1973
static Result work(std::size_t node_id, const Task &task, const std::tuple< std::shared_future< ParentResults >...> &futures)
Definition: transwarp.h:703
void execute(const std::function< void()> &functor, const std::shared_ptr< transwarp::node > &) override
Pushes the functor into the thread pool for asynchronous execution.
Definition: transwarp.h:1129
The accept type. Used for tag dispatch.
Definition: transwarp.h:61
const std::shared_future< result_type > & get_future() const noexceptoverride
Returns the future associated to the underlying execution.
Definition: transwarp.h:1246
constexpr transwarp::accept_type accept
The accept task tag.
Definition: transwarp.h:62
Determines the result type of the Functor dispatching on the task type.
Definition: transwarp.h:978
An exception for errors in the thread_pool class.
Definition: transwarp.h:417
TaskType task_type
The task type.
Definition: transwarp.h:1148
void schedule_all(transwarp::executor &, transwarp::schedule_type, bool) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1955
bool has_result() const noexceptoverride
Returns whether this task contains a result.
Definition: transwarp.h:1402
The listener interface.
Definition: transwarp.h:267
Exception thrown when a task is canceled.
Definition: transwarp.h:399
TaskType task_type
The task type.
Definition: transwarp.h:1782
void wait() const override
Waits for the task to complete. Should only be called if was_scheduled() is true, throws transwarp::t...
Definition: transwarp.h:1389
Scheduling according to a depth-first search.
std::size_t get_level() const noexcept
The task level.
Definition: transwarp.h:124
std::shared_future< ResultType > make_future_with_value(Value &&value)
Returns a ready future with the given value as its state.
Definition: transwarp.h:1058
std::string get_name() const override
Returns the name of the executor.
Definition: transwarp.h:1098
void schedule() override
Schedules this task for execution on the caller thread. The task-specific executor gets precedence if...
Definition: transwarp.h:1274
void add_listener(std::shared_ptr< transwarp::listener >) override
No-op because a value task doesn't raise events.
Definition: transwarp.h:1916
void add_listener(std::shared_ptr< transwarp::listener > listener) override
Adds a new listener.
Definition: transwarp.h:1256
void ensure_task_not_running() const
Checks if the task is currently running and throws transwarp::transwarp_error if it is...
Definition: transwarp.h:1466
Removes custom data from the given task.
Definition: transwarp.h:937
void schedule_all(transwarp::executor &, bool) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1943
Resets the given task.
Definition: transwarp.h:864
const std::shared_ptr< std::string > & get_name() const noexcept
The optional task name (may be null)
Definition: transwarp.h:134
void set_value(const typename transwarp::remove_refc< result_type >::type &value) override
Assigns a value to this task. Scheduling will have no effect after a value has been set...
Definition: transwarp.h:1629
A base class for a user-defined functor that needs access to the node associated to the task or a can...
Definition: transwarp.h:427
constexpr transwarp::consume_any_type consume_any
The consume_any task tag.
Definition: transwarp.h:74
bool is_canceled() const noexcept
Returns whether the associated task is canceled.
Definition: transwarp.h:159
A node carrying meta-data of a task.
Definition: transwarp.h:107
Result call_with_futures(std::size_t node_id, const Task &task, const std::tuple< std::shared_future< ParentResults >...> &futures)
Calls the functor of the given task with the results from the futures. Throws transwarp::task_cancele...
Definition: transwarp.h:741
ResultType result_type
The result type of this task.
Definition: transwarp.h:1151
Resets the priority of the given task.
Definition: transwarp.h:917
void schedule() override
No-op because a value task never runs.
Definition: transwarp.h:1922
void wait() const override
No-op because a value task never runs.
Definition: transwarp.h:1978
void schedule_all(transwarp::executor &executor, transwarp::schedule_type type) override
Schedules all tasks in the graph for execution using the provided executor. The task-specific executo...
Definition: transwarp.h:1350
std::size_t get_priority() const noexcept
The task priority (defaults to 0)
Definition: transwarp.h:149
const std::shared_ptr< transwarp::node > & get_parent() const noexcept
Returns the parent node.
Definition: transwarp.h:212
A task for non-void result type. A task representing a piece of work given by functor and parent task...
Definition: transwarp.h:1619
void transwarp_cancel_point() const
If the associated task is canceled then this will throw transwarp::task_canceled which will stop the ...
Definition: transwarp.h:441
Returns the result type of a std::shared_future<T>
Definition: transwarp.h:343
auto make_value_task(std::string name, Value &&value) -> decltype(std::make_shared< transwarp::value_task< typename std::decay< Value >::type >>(std::move(name), std::forward< Value >(value)))
A factory function to create a new value task.
Definition: transwarp.h:2068
The base task class that contains the functionality that can be used with all result types (void and ...
Definition: transwarp.h:1144
Definition: transwarp.h:787
void set_value(typename transwarp::remove_refc< result_type >::type &&value) override
Assigns a value to this task.
Definition: transwarp.h:1963
The task's functor consumes all parent results.
void remove_listener(const std::shared_ptr< transwarp::listener > &) override
No-op because a value task doesn't raise events.
Definition: transwarp.h:1919
void set_priority_all(std::size_t priority) override
Sets a priority to all tasks (defaults to 0). transwarp will not directly use this. This is only useful if something else is using the priority.
Definition: transwarp.h:1866
Base class for exceptions.
Definition: transwarp.h:390
void schedule_all(transwarp::schedule_type) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1946
task_impl(std::string name, F &&functor, std::shared_ptr< transwarp::task< ParentResults >>...parents)
A task is defined by name, functor, and parent tasks. name is optional, see overload Note: A task mus...
Definition: transwarp.h:1792
constexpr transwarp::consume_type consume
The consume task tag.
Definition: transwarp.h:70
std::size_t get_id() const noexcept
The task ID.
Definition: transwarp.h:119
void schedule(transwarp::executor &, bool) override
No-op because a value task never runs.
Definition: transwarp.h:1931
A value task that stores a single value and doesn't require scheduling. Value tasks should be created...
Definition: transwarp.h:1815
void reset_priority() override
Resets the task priority to 0.
Definition: transwarp.h:1871
void remove_listener(const std::shared_ptr< transwarp::listener > &listener) override
Removes a listener.
Definition: transwarp.h:1264
const std::shared_ptr< transwarp::node > & transwarp_node() const noexcept
The node associated to the task.
Definition: transwarp.h:435
just after a task has started running (handle_event called on thread that task is run on) ...
void reset_all() override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1999
Assigns custom data to the given task.
Definition: transwarp.h:925
The task's functor takes no arguments but waits for all parents to finish.
void set_exception(std::exception_ptr exception) override
Assigns an exception to this task. Scheduling will have no effect after an exception has been set...
Definition: transwarp.h:1375
const std::shared_ptr< void > & get_custom_data() const noexcept
The custom task data (may be null)
Definition: transwarp.h:154
void call_with_each(const Functor &f, const std::tuple< std::shared_ptr< transwarp::task< ParentResults >>...> &t)
Calls the functor with every element in the tuple. Expects the tuple to contain task pointers only an...
Definition: transwarp.h:780
void reset_priority() override
Resets the task priority to 0.
Definition: transwarp.h:1202
typename transwarp::detail::result< TaskType, Functor, ParentResults...>::type result_type
The result type of this task.
Definition: transwarp.h:1785
void schedule_all(transwarp::executor &, transwarp::schedule_type) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1949
void schedule_all(transwarp::schedule_type, bool) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1952
An edge between two nodes.
Definition: transwarp.h:198
const std::shared_ptr< transwarp::node > & get_child() const noexcept
Returns the child node.
Definition: transwarp.h:217
void schedule_all(transwarp::schedule_type type) override
Schedules all tasks in the graph for execution on the caller thread. The task-specific executors get ...
Definition: transwarp.h:1342
std::vector< transwarp::edge > get_graph() const override
Returns the graph of the task structure. This is mainly for visualizing the tasks and their interdepe...
Definition: transwarp.h:1440
void schedule(transwarp::executor &) override
No-op because a value task never runs.
Definition: transwarp.h:1925
void reset_all() override
Resets the futures of all tasks in the graph.
Definition: transwarp.h:1414
ResultType result_type
The result type of this task.
Definition: transwarp.h:1821
Executor for parallel execution. Uses a simple thread pool.
Definition: transwarp.h:1110
The wait_any type. Used for tag dispatch.
Definition: transwarp.h:81
void set_priority_all(std::size_t priority) override
Sets a priority to all tasks (defaults to 0). transwarp will not directly use this. This is only useful if something else is using the priority (e.g. a custom executor)
Definition: transwarp.h:1195
void schedule(bool reset) override
Schedules this task for execution on the caller thread. The task-specific executor gets precedence if...
Definition: transwarp.h:1283
virtual std::string get_name() const =0
Is supposed to return the name of the executor.
std::string to_string(const transwarp::task_type &type)
String conversion for the task_type enumeration.
Definition: transwarp.h:42
virtual void execute(const std::function< void()> &functor, const std::shared_ptr< transwarp::node > &node)=0
Is supposed to run a task which is wrapped by the functor. The functor only captures a shared_ptr and...
void execute(const std::function< void()> &functor, const std::shared_ptr< transwarp::node > &) override
Runs the functor on the current thread.
Definition: transwarp.h:1103
void remove_executor() override
Removes the executor from this task.
Definition: transwarp.h:1173
The accept_any type. Used for tag dispatch.
Definition: transwarp.h:65
transwarp::task_type get_type() const noexcept
The task type.
Definition: transwarp.h:129
static bool wait(const T &arg, const Args &...args)
Definition: transwarp.h:724
virtual void handle_event(transwarp::event_type event, const std::shared_ptr< transwarp::node > &node)=0
This may be called from arbitrary threads.
bool is_ready() const override
Returns true because a value task is always ready.
Definition: transwarp.h:1981
constexpr transwarp::wait_type wait
The wait task tag.
Definition: transwarp.h:78
The root type. Used for tag dispatch.
Definition: transwarp.h:57
The task's functor consumes the first parent result that becomes ready.
A task representing a piece of work given by functor and parent tasks. By connecting tasks a directed...
Definition: transwarp.h:1779
The wait type. Used for tag dispatch.
Definition: transwarp.h:77
void cancel(bool enabled) noexceptoverride
If enabled then this task is canceled which will throw transwarp::task_canceled when retrieving the t...
Definition: transwarp.h:1424
Schedules using the given executor.
Definition: transwarp.h:851
constexpr transwarp::root_type root
The root task tag.
Definition: transwarp.h:58
void remove_custom_data() override
Removes custom data from this task.
Definition: transwarp.h:1896
void schedule_all(transwarp::executor &executor) override
Schedules all tasks in the graph for execution using the provided executor. The task-specific executo...
Definition: transwarp.h:1316
schedule_type
Determines in which order tasks are scheduled in the graph.
Definition: transwarp.h:86
The task's functor accepts all parent futures.
Applies final bookkeeping to the task.
Definition: transwarp.h:824
void remove_executor_all() override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1856
void schedule(transwarp::executor &executor, bool reset) override
Schedules this task for execution using the provided executor. The task-specific executor gets preced...
Definition: transwarp.h:1300
std::vector< transwarp::edge > get_graph() const override
Returns an empty graph because a value task doesn't have parents.
Definition: transwarp.h:2008
const std::shared_ptr< transwarp::node > & get_node() const noexceptoverride
Returns the associated node.
Definition: transwarp.h:1251
task_type
The possible task types.
Definition: transwarp.h:31
void set_value() override
Assigns a value to this task. Scheduling will have no effect after a call to this. Calling reset() will reset this and re-enable scheduling.
Definition: transwarp.h:1741
event_type
An enum of task events used with the listener pattern.
Definition: transwarp.h:259
The task's functor takes no arguments but waits for the first parent to finish.
void remove_custom_data_all() override
Removes custom data from all tasks.
Definition: transwarp.h:1239
static Result work(std::size_t node_id, const Task &task, const std::tuple< std::shared_future< ParentResults >...> &futures)
Definition: transwarp.h:674
void set_value(typename transwarp::remove_refc< result_type >::type &&value) override
Assigns a value to this task. Scheduling will have no effect after a value has been set...
Definition: transwarp.h:1635
auto make_task(TaskType, std::string name, Functor &&functor, std::shared_ptr< Parents >...parents) -> decltype(std::make_shared< transwarp::task_impl< TaskType, typename std::decay< Functor >::type, typename Parents::result_type...>>(std::move(name), std::forward< Functor >(functor), std::move(parents)...))
A factory function to create a new task.
Definition: transwarp.h:2053
void reset() override
No-op because a value task never runs.
Definition: transwarp.h:1996
std::shared_future< void > make_ready_future()
Returns a ready future.
Definition: transwarp.h:1065
void set_executor_all(std::shared_ptr< transwarp::executor >) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1850
constexpr transwarp::accept_any_type accept_any
The accept_any task tag.
Definition: transwarp.h:66
const std::shared_future< result_type > & get_future() const noexceptoverride
Returns the future associated to the underlying execution.
Definition: transwarp.h:1906
Cancels or resumes the given task.
Definition: transwarp.h:873
void remove_executor() override
No-op because a value task never runs.
Definition: transwarp.h:1853
void schedule(bool) override
No-op because a value task never runs.
Definition: transwarp.h:1928
void schedule_all(bool) override
No-op because a value task never runs and doesn't have parents.
Definition: transwarp.h:1940
Visits the given task using the visitor given in the constructor.
Definition: transwarp.h:957
Pushes the given task into the vector of tasks.
Definition: transwarp.h:945
Executor for sequential execution. Runs functors sequentially on the same thread. ...
Definition: transwarp.h:1086
FutureResult wait_for_any(const std::shared_future< ParentResults > &...futures)
Waits for the first future to finish.
Definition: transwarp.h:635
bool has_result() const noexceptoverride
Returns true because a value task always contains a result.
Definition: transwarp.h:1986
std::shared_future< ResultType > make_future_with_exception(std::exception_ptr exception)
Returns a ready future with the given exception as its state.
Definition: transwarp.h:1073
void remove_executor_all() override
Removes the executor from all tasks.
Definition: transwarp.h:1180
const std::shared_ptr< transwarp::node > & get_node() const noexceptoverride
Returns the associated node.
Definition: transwarp.h:1911
bool is_ready() const override
Returns whether the task has finished processing. Should only be called if was_scheduled() is true...
Definition: transwarp.h:1396
task_impl(F &&functor, std::shared_ptr< transwarp::task< ParentResults >>...parents)
This overload is for omitting the task name Note: A task must be created using shared_ptr (because of...
Definition: transwarp.h:1800
An interface for the task class.
Definition: transwarp.h:277