Lely core libraries  2.3.4
co_task.hpp
Go to the documentation of this file.
1 
24 #ifndef LELY_EV_CO_TASK_HPP_
25 #define LELY_EV_CO_TASK_HPP_
26 
27 #include <lely/ev/exec.hpp>
28 #include <lely/util/coroutine.hpp>
29 
30 namespace lely {
31 namespace ev {
32 
34 class CoTask : public ev_task, public util::Coroutine {
35  public:
37  explicit CoTask(ev_exec_t* exec) noexcept
38  : ev_task EV_TASK_INIT(exec, [](ev_task* task) noexcept {
39  auto self = static_cast<CoTask*>(task);
40  (*self)();
41  }) {}
42 
44  CoTask() noexcept : CoTask(nullptr) {}
45 
46  virtual ~CoTask() = default;
47 
49  Executor
50  get_executor() const noexcept {
51  return Executor(exec);
52  }
53 
55  virtual void operator()() noexcept = 0;
56 };
57 
58 } // namespace ev
59 } // namespace lely
60 
61 #endif // !LELY_EV_CO_TASK_HPP_
ev_exec_t
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
coroutine.hpp
lely::ev::CoTask::get_executor
Executor get_executor() const noexcept
Returns the executor to which the task is (to be) submitted.
Definition: co_task.hpp:50
lely::ev::CoTask::CoTask
CoTask() noexcept
Constructs a coroutine task.
Definition: co_task.hpp:44
lely::ev::Executor
An abstract task executor. This class is a wrapper around #ev_exec_t*.
Definition: exec.hpp:38
lely::util::Coroutine
The parent class for function objects used as stackless coroutines.
Definition: coroutine.hpp:48
lely::ev::CoTask
A stackless coroutine which can be submitted to an executor as a task.
Definition: co_task.hpp:34
lely::ev::CoTask::CoTask
CoTask(ev_exec_t *exec) noexcept
Constructs a coroutine task with an associated executor (can be nullptr).
Definition: co_task.hpp:37
ev_task
An executable task.
Definition: task.h:41
lely::ev::CoTask::operator()
virtual void operator()() noexcept=0
The coroutine to be executed when the task is run.
EV_TASK_INIT
#define EV_TASK_INIT(exec, func)
The static initializer for ev_task.
Definition: task.h:53
exec.hpp
ev_task::exec
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43