12 #include <condition_variable> 56 bool done()
const {
return _is_done; }
67 std::string _debug_name =
"";
68 std::unique_ptr<InnerControl> _inner;
69 std::unique_ptr<Thread> _thread;
70 std::atomic<bool> _is_done {
false };
72 std::condition_variable _cond;
73 std::atomic<bool> _control_is_outer {
true };
74 std::atomic<bool> _abort {
false };
86 double time()
const {
return _time; }
89 template<
typename Fun>
98 void wait_sec(
double s);
104 void poll(
double dt);
117 bool empty()
const {
return _list.empty(); }
118 size_t size()
const {
return _list.size(); }
124 std::shared_ptr<Coroutine> start(
const char* debug_name, std::function<
void(
InnerControl& ic)> fun);
128 bool erase(
const std::shared_ptr<Coroutine>& cr);
132 void poll(
double dt);
135 std::vector<std::shared_ptr<Coroutine>> _list;
~Coroutine()
Will stop() the coroutine, if not already done().
double time() const
Total running time of this coroutine (sum of all dt).
Definition: coroutine.hpp:86
void wait_for(const Fun &fun)
Inner thread: return execution to Outer thread until fun() is true.
Definition: coroutine.hpp:90
void stop()
Abort the inner thread, if not done().
void poll(double dt)
dt = elapsed time since last call in seconds.
bool done() const
Has the inner thread finished its execution?
Definition: coroutine.hpp:56
Coroutine(const char *debug_name, std::function< void(InnerControl &ic)> fun)
Definition: coroutine.hpp:80
This acts like a coroutine, but is implemented as a separate thread.
Definition: coroutine.hpp:39
Helper for handling several coroutines.
Definition: coroutine.hpp:114
Definition: coroutine.hpp:18