11#ifndef CONCURRENCPP_EXECUTOR_H
22#define CONCURRENCPP_EXECUTOR_H
33
4+ #include " concurrencpp/task.h"
45#include " concurrencpp/results/result.h"
56
67#include < span>
8+ #include < vector>
79#include < string>
810#include < string_view>
911
@@ -16,27 +18,13 @@ namespace concurrencpp {
1618 class executor {
1719
1820 private:
19- template <class executor_type , class callable_type , class ... argument_types>
20- static null_result post_bridge (executor_tag, executor_type*, callable_type callable, argument_types... arguments) {
21- callable (arguments...);
22- co_return ;
23- }
24-
25- template <class callable_type >
26- static null_result bulk_post_bridge (details::executor_bulk_tag, std::vector<std::experimental::coroutine_handle<>>* accumulator, callable_type callable) {
27- callable ();
28- co_return ;
29- }
30-
3121 template <class return_type , class executor_type , class callable_type , class ... argument_types>
3222 static result<return_type> submit_bridge (executor_tag, executor_type*, callable_type callable, argument_types... arguments) {
3323 co_return callable (arguments...);
3424 }
3525
3626 template <class callable_type , class return_type = typename std::invoke_result_t <callable_type>>
37- static result<return_type> bulk_submit_bridge (details::executor_bulk_tag,
38- std::vector<std::experimental::coroutine_handle<>>* accumulator,
39- callable_type callable) {
27+ static result<return_type> bulk_submit_bridge (details::executor_bulk_tag, std::vector<concurrencpp::task>* accumulator, callable_type callable) {
4028 co_return callable ();
4129 }
4230
@@ -46,7 +34,8 @@ namespace concurrencpp {
4634 static_assert (std::is_invocable_v<callable_type, argument_types...>,
4735 " concurrencpp::executor::post - <<callable_type>> is not invokable with <<argument_types...>>" );
4836
49- post_bridge ({}, executor_ptr, std::forward<callable_type>(callable), std::forward<argument_types>(arguments)...);
37+ assert (executor_ptr != nullptr );
38+ executor_ptr->enqueue (details::bind_with_try_catch (std::forward<callable_type>(callable), std::forward<argument_types>(arguments)...));
5039 }
5140
5241 template <class executor_type , class callable_type , class ... argument_types>
@@ -55,37 +44,40 @@ namespace concurrencpp {
5544 " concurrencpp::executor::submit - <<callable_type>> is not invokable with <<argument_types...>>" );
5645
5746 using return_type = typename std::invoke_result_t <callable_type, argument_types...>;
58-
5947 return submit_bridge<return_type>({}, executor_ptr, std::forward<callable_type>(callable), std::forward<argument_types>(arguments)...);
6048 }
6149
6250 template <class executor_type , class callable_type >
6351 static void do_bulk_post (executor_type* executor_ptr, std::span<callable_type> callable_list) {
64- std::vector<std::experimental::coroutine_handle<>> accumulator;
65- accumulator.reserve (callable_list.size ());
52+ assert (executor_ptr != nullptr );
53+ assert (!callable_list.empty ());
54+
55+ std::vector<task> tasks;
56+ tasks.reserve (callable_list.size ());
6657
6758 for (auto & callable : callable_list) {
68- bulk_post_bridge<callable_type>({}, &accumulator, std::move (callable));
59+ tasks. emplace_back ( details::bind_with_try_catch ( std::move (callable) ));
6960 }
7061
71- assert (!accumulator. empty ()) ;
72- executor_ptr->enqueue (accumulator );
62+ std::span<task> span = tasks ;
63+ executor_ptr->enqueue (span );
7364 }
7465
7566 template <class executor_type , class callable_type , class return_type = std::invoke_result_t <callable_type>>
7667 static std::vector<concurrencpp::result<return_type>> do_bulk_submit (executor_type* executor_ptr, std::span<callable_type> callable_list) {
77- std::vector<std::experimental::coroutine_handle<> > accumulator;
68+ std::vector<task > accumulator;
7869 accumulator.reserve (callable_list.size ());
7970
80- std::vector<concurrencpp:: result<return_type>> results;
71+ std::vector<result<return_type>> results;
8172 results.reserve (callable_list.size ());
8273
8374 for (auto & callable : callable_list) {
8475 results.emplace_back (bulk_submit_bridge<callable_type>({}, &accumulator, std::move (callable)));
8576 }
8677
8778 assert (!accumulator.empty ());
88- executor_ptr->enqueue (accumulator);
79+ std::span<task> span = accumulator;
80+ executor_ptr->enqueue (span);
8981 return results;
9082 }
9183
@@ -96,8 +88,8 @@ namespace concurrencpp {
9688
9789 const std::string name;
9890
99- virtual void enqueue (std::experimental::coroutine_handle<> task) = 0;
100- virtual void enqueue (std::span<std::experimental::coroutine_handle<> > tasks) = 0;
91+ virtual void enqueue (concurrencpp::task task) = 0;
92+ virtual void enqueue (std::span<concurrencpp::task > tasks) = 0;
10193
10294 virtual int max_concurrency_level () const noexcept = 0;
10395
0 commit comments