|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
|
|
#include <vector>
|
|
#include <vector>
|
|
|
#include <memory>
|
|
#include <memory>
|
|
|
|
|
+#include <cassert>
|
|
|
#include <utility>
|
|
#include <utility>
|
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
#include <type_traits>
|
|
#include <type_traits>
|
|
@@ -57,12 +58,16 @@ class scheduler final {
|
|
|
struct continuation final {
|
|
struct continuation final {
|
|
|
continuation(process_handler *handler)
|
|
continuation(process_handler *handler)
|
|
|
: handler{handler}
|
|
: handler{handler}
|
|
|
- {}
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ assert(handler);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
template<typename Proc, typename... Args>
|
|
template<typename Proc, typename... Args>
|
|
|
continuation then(Args &&... args) {
|
|
continuation then(Args &&... args) {
|
|
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>);
|
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>);
|
|
|
- handler = scheduler::then<Proc>(handler, std::forward<Args>(args)...);
|
|
|
|
|
|
|
+ auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
|
|
|
|
+ handler->next.reset(new process_handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr});
|
|
|
|
|
+ handler = handler->next.get();
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -104,17 +109,6 @@ class scheduler final {
|
|
|
delete static_cast<Proc *>(proc);
|
|
delete static_cast<Proc *>(proc);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- template<typename Proc, typename... Args>
|
|
|
|
|
- static auto then(process_handler *handler, Args &&... args) {
|
|
|
|
|
- if(handler) {
|
|
|
|
|
- auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
|
|
|
|
- handler->next.reset(new process_handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr});
|
|
|
|
|
- handler = handler->next.get();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return handler;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public:
|
|
public:
|
|
|
/*! @brief Unsigned integer type. */
|
|
/*! @brief Unsigned integer type. */
|
|
|
using size_type = typename std::vector<process_handler>::size_type;
|
|
using size_type = typename std::vector<process_handler>::size_type;
|
|
@@ -186,11 +180,9 @@ public:
|
|
|
template<typename Proc, typename... Args>
|
|
template<typename Proc, typename... Args>
|
|
|
auto attach(Args &&... args) {
|
|
auto attach(Args &&... args) {
|
|
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>);
|
|
static_assert(std::is_base_of_v<process<Proc, Delta>, Proc>);
|
|
|
-
|
|
|
|
|
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
|
auto proc = typename process_handler::instance_type{new Proc{std::forward<Args>(args)...}, &scheduler::deleter<Proc>};
|
|
|
process_handler handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr};
|
|
process_handler handler{std::move(proc), &scheduler::update<Proc>, &scheduler::abort<Proc>, nullptr};
|
|
|
handlers.push_back(std::move(handler));
|
|
handlers.push_back(std::move(handler));
|
|
|
-
|
|
|
|
|
return continuation{&handlers.back()};
|
|
return continuation{&handlers.back()};
|
|
|
}
|
|
}
|
|
|
|
|
|